voici mon code au complet
Oui en faite, je ne savais pas pour le warning!!lol
Merci..Mais maintenant, j'ai des erreurs dans la compilation.
Ma classe 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
| import java.io.IOException;
import java.io.*;
class Compte
{
static int num_Compte=0 ;
private int solde ;
Compte()
{
num_Compte++;
solde=0;
}
public void deposer(int s)
{
solde = solde + s ;
}
public void retirer(int s)//: pour retirer une somme sur le compte.
{
solde = solde-s ;
}
public int avoirSolde()// qui retourne le solde du compte.
{
return solde;
}
public void infos()
{
System.out.print ("Compte numéro"+num_Compte+ "," + "Solde :" + avoirSolde()) ;
}
public static void main(String[] args) throws IOException
{
BufferedReader clavier = new BufferedReader(new InputStreamReader(System.in));
int chaine = Integer.parseInt(clavier.readLine());
System.out.print(chaine);
Compte david = new Compte();
david.deposer(5000);
int n;
n = david.avoirSolde();
System.out.println(n);
david.retirer(200);
david.infos();
Compte Jean = new Compte();
Jean.infos();
}
} |
Ma classe DAB(Distributeur automatique de billets)
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 92 93 94 95 96
| import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class DAB {
private int taille;
private Compte inconnu[];
private int numCompteCour;
DAB(int n)
{
taille = n;
this.inconnu = new Compte[taille];
for (int i=1;i<taille+1;i=i+1)
{
this.inconnu[i] = new Compte();
}
this.numCompteCour=0;
}
public void activer() throws IOException
{
System.out.println("Menu");
System.out.println("0.Selectionnez un compte courant");
System.out.println("1.Retrait");
System.out.println("2.Depot");
System.out.println("3.Solde");
System.out.println("4.Quit");
int n=System.in.read();
while (n!=4)
{
System.out.println("Menu");
System.out.println("0.Selectionnez un compte courant");
System.out.println("1.Retrait");
System.out.println("2.Depot");
System.out.println("3.Solde");
System.out.println("4.Quit");
n=System.in.read();
if (n==0)
{
System.out.println("Entrez le numero du compte courant");
int numcompte = System.in.read();
if (numcompte<0 || numcompte>n)
{
System.out.println("entrez un numero situé entre 0 et "+taille);
}
else
{
numCompteCour = numcompte;
}
}
else if (n==1)
{
String str="Retrait";
System.out.println("vous avez choisi le choix"+n+"."+str);
System.out.println("Entrez le montant que vous voulez retirer");
int p = System.in.read();
inconnu[numCompteCour].retirer(p);
}
else if (n==2)
{String m="Depot";
System.out.println("vous avez choisi le choix"+n+"."+m);
System.out.println("Entrez le montant que vous voulez deposer");
int p = System.in.read();
inconnu[numCompteCour].deposer(p);
}
else if (n==3)
{String m="Solde";
System.out.println("vous avez choisi le choix"+n+"."+m);
inconnu[numCompteCour].avoirSolde();
}
else
{System.out.println("Le numero de votre choix doit se situé entre 1 et 4");
}
}
}
public static void main(String[]args) throws java.io.IOException
{
BufferedReader clavier;
clavier = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Entrez le nombre de compte");
int numChoisi = Integer.parseInt(clavier.readLine());
System.out.print(numChoisi);
DAB bnp = new DAB(numChoisi);
bnp.activer();
}
} |
En le compilant, j'ai une erreur de
[code]
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at DAB.<init>(DAB.java:16)
at DAB.main(DAB.java:92)
code]
Merci