class compte{
private double solde;
public compte(float solde){
this.solde=solde;
}
public double getSolde(){
return solde;
}
void retirer(double ret){
if(ret>solde){
System.out.println("fonds insuffisants pour retirer"+ret+"d.");
}else{
solde-=ret;
System.out.println("Retrait de"+ret+"deffectue.");
}
}
void deposer(double dep){
this.solde+=dep;
}
void transfer(compte c2,int nb){
if(nb>solde){
System.out.println("Fond insuffisants pour transfere"+nb+"d.");
}else{
retirer(nb);
c2.deposer(nb);
}
}
public static void main (String[] args){
compte c1=new compte(500);
compte c2=new compte(0);
c1.retirer(100);
c1.deposer(200);
c1.transfer(c2,300);
System.out.println("compte 1="+c1.getSolde());
System.out.println ("compte 2="+c2.getSolde());
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter