Bonjour, j'ai quelques soucis avec la prog. objet:
J'ai un tableau de 3 valeurs pour chaque client. Je saisi tout au clavier. J'ai fait une methode pour afficher la saisi, une autre pour la somme du tableau.
Mon problème c'est qu'il affiche rien avec les methodes, je n'ai pas d'erreur à la compilation et je saisi bien mes valeurs au clavier.
J'ai essayé une boucle dans le main, il m'affiche toujours le même tableau, le dernier saisi.
Merci de votre aide,j'aimerai bien comprendre mes erreurs et arriver à faire de prog.objet!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 import java.util.Scanner; class Compte{ String Nom; double[]SommeMois; Compte(String Nom){ //constructeur this.Nom=Nom; this.SommeMois=new double[3]; } Compte(){ //constructeur this.Nom=Nom; this.SommeMois=new double[3]; } void afficherCompteClient(){ System.out.println("nom du client: " + this.Nom); System.out.println("Somme par Mois:"); for(int i=0; i<this.SommeMois.length;i++) System.out.println("Somme du mois " + (i+1) + "=" +this.SommeMois[i]); } void afficherSommeTrimestre(){ System.out.println("nom du client: " + this.Nom); double somme=0.0; for(int i=0; i<this.SommeMois.length;i++) somme=somme + this.SommeMois[i]; System.out.println("Somme par Trimestre: " + somme); } } public class EssaiClassTab{ public static void main(String[]args){ double somme=0.0; Scanner sc = new Scanner(System.in); System.out.print("Combien de clients:"); int n =sc.nextInt(); System.out.println(" "); Compte[]tabCompte=new Compte[n]; double[]SommeMois=new double[3]; for (int i=0;i<tabCompte.length;i++){ tabCompte[i]=new Compte(); System.out.print("saisir nom Client" +( i+1) + " : "); tabCompte[i].Nom=sc.nextLine(); sc.nextLine(); for (int j=0;j<SommeMois.length;j++){ System.out.print("saisir Somme du Client " + (i+1) + " : "); SommeMois[j]=sc.nextDouble(); //OK } System.out.println(" "); } System.out.println("" + tabCompte[0].Nom + tabCompte[0].SommeMois); System.out.println(" "); tabCompte[0].afficherCompteClient(); System.out.println(" "); tabCompte[0].afficherSommeTrimestre(); System.out.println(" "); for (int i=0;i<tabCompte.length;i++){ System.out.println("nom du client: " + tabCompte[i].Nom); for(int j=0; j<SommeMois.length;j++){ System.out.println("Somme du mois " + (j+1) + "=" + SommeMois[j]); somme+=SommeMois[j]; } System.out.println("Somme par Trimestre: " + somme); System.out.println(" "); } } }
Partager