Récupérer informations client
Bonjour,
Je développe une petite application de gestion de compte et j'ai un problème quand je suis dans ma classe DAB: je n'arrive pas à récupérer les comptes du client lorsqu'il choisit le choix: afficher le bilan de mes comptes.
voici mes différentes classes:
Client:
Code:
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
| package banque;
public class Client {
protected String nom;
protected String prenom;
protected String adresse;
protected Compte compte[] = new Compte[3];
protected int i = 0;
public Client (String nom, String prenom, String adresse){
this.nom = nom;
this.prenom = prenom;
this.adresse = adresse;
}
public Client (String nom){
this.nom = nom;
}
public void ajouterCompte(Compte unCompte){
compte[i] = unCompte;
i++;
}
public void afficher(){
System.out.print("Bilan des comptes de M. ou Mme "+nom+"\n");
for(int j=0; j<i; j++){
compte[j].afficher();
}
}
public void afficherComptes()
{
for(int j = 0 ; j < i; j++)
{
System.out.println(j+1 +") Compte n°"+ compte[j].getNumero());
}
}
public String getNom(){
return nom;
}
public String getPrenom() {
return prenom;
}
public Compte[] getComptes() {
return compte;
}
} |
Compte:
Code:
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| package banque;
public class Compte {
protected int numero = 0;
protected float solde;
protected float decouvertMax;
protected float debitMax;
public int getNumero(){
return numero;
}
public Compte (int n){
this.numero = n;
this.solde = 0;
this.decouvertMax = 800;
this.debitMax = 1000;
}
public Compte (int n, float s){
this.numero = n;
this.solde = s;
this.decouvertMax = 800;
this.debitMax = 1000;
}
public Compte (int numero, float solde, float decouvertMax){
this.numero = numero;
this.solde = solde;
this.decouvertMax = decouvertMax;
this.debitMax = 1000;
}
public Compte (float debitMax, int numero, float solde){
this.numero = numero;
this.solde = solde;
this.decouvertMax = 800;
this.debitMax = debitMax;
}
public Compte (int numero, float solde, float decouvertMax, float debitMax){
this.numero = numero;
this.solde = solde;
this.decouvertMax = decouvertMax;
this.debitMax = debitMax;
}
public void afficher(){
System.out.println("Compte numéro : "+numero+", Solde : "+solde);
}
public float getDecouvertMax(){
return decouvertMax;
}
public void setDecouvertMax(float nouvDecouvertMax){
decouvertMax = nouvDecouvertMax;
}
public float getDebitMax(){
return debitMax;
}
public void setDebitMax(float nouvDebitMax){
debitMax = nouvDebitMax;
}
public void depot(float montant){
solde = solde + montant;
}
public float getSolde(){
return solde;
}
public boolean retrait(float montant){
if(montant <= debitMax && montant <= solde+decouvertMax){
solde = solde - montant;
return true;
}else{
return false;
}
}
public void virement(float montantDep, Compte compteDest){
boolean debit= this.retrait( montantDep);
if (debit == true){
compteDest.depot(montantDep);
}
}
} |
Banque:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| package banque;
public class Banque {
protected Client tabClients[]= new Client[10];
protected int i = 0;
public void ajouterClient(Client c)
{
tabClients[i]=c;
i++;
}
public void afficherClients()
{
for(int j = 0 ; j < i; j++)
{
System.out.println(j+1 +") " + tabClients[j].getNom());
}
}
public Client[] getTabClients(){
return tabClients;
}
} |
DAB
Code:
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
| package banque.dab;
import java.util.Scanner;
import banque.Banque;
import banque.Client;
public class DAB {
Banque banque;
public DAB(){
}
public void initialiser(Banque uneBanque){
this.banque = uneBanque;
}
public void demarrer(){
chargerClients();
Scanner sc = new Scanner(System.in);
int choixClient = sc.nextInt();
if(choixClient != 0){
Client nomClient = new Client(banque.getTabClients()[choixClient-1].getNom());
System.out.println("Bonjour M. ou Mme "+nomClient);
menuOperation();
int choixOperation = sc.nextInt();
switch(choixOperation){
case 0:
chargerClients();
case 1:
operationCompte();
case 2:
case 3:
nomClient.afficher(); // affiche les comptes du client
}
}
}
private void chargerClients(){
System.out.println("Quel est votre nom ?");
banque.afficherClients();
System.out.println("0) Quitter");
}
private void menuOperation(){
System.out.println("Quelle operation voulez-vous effectuer ?");
System.out.println("0) Revenir au menu principal");
System.out.println("1) Effectuer une opération sur un compte");
System.out.println("2) Faire un virement");
System.out.println("3) Afficher le bilan de vos comptes");
}
private void operationCompte(){
System.out.println("Quelle opération voulez-vous effectuer sur le compte ?");
System.out.println("0) Retour");
System.out.println("1) Faire un retrait");
System.out.println("2) Faire un dépot");
System.out.println("3) Afficher le solde");
}
} |
TesterCompte
Code:
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
| package banque.test;
import banque.Banque;
import banque.Client;
import banque.Compte;
import banque.dab.DAB;
public class TesterCompte {
public static void main(String[] args) {
Compte compte1 = new Compte(1);
Compte compte2 = new Compte(2);
compte1.afficher();
compte2.afficher();
compte1.depot(5000);
compte1.afficher();
compte1.retrait(200);
compte1.afficher();
compte1.virement(600, compte2);
compte1.afficher();
compte2.afficher();
Client client1 = new Client ("toto", "toto", "CRETEIL");
client1.ajouterCompte(compte1);
client1.ajouterCompte(compte2);
client1.afficher();
client1.afficherComptes();
Banque banque1 = new Banque();
banque1.ajouterClient(client1);
banque1.afficherClients();
DAB dab = new DAB();
dab.initialiser(banque1);
dab.demarrer();
}
} |
C'est ici que sa bloque:
Code:
1 2 3
| case 3:
nomClient.afficher(); // affiche les comptes du client
} |
Il m'affiche juste sa:
Code:
System.out.print("Bilan des comptes de M. ou Mme "+nom+"\n");
Merci de votre aide