Created
April 9, 2020 13:41
-
-
Save GravenilvecTV/5d62378f164592ce6055a8a58e37e33e to your computer and use it in GitHub Desktop.
Correction TP 21/30 - Java 4 - Banque
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CompteCourant { | |
// attributs | |
private String nomProprietaire; | |
private int montant; | |
private int decouvertAutorise; | |
// constructeur | |
public CompteCourant(String nomProprietaire, int montant){ | |
this.nomProprietaire = nomProprietaire; | |
this.montant = montant; | |
this.decouvertAutorise = 0; | |
} | |
// methodes | |
public void afficherSolde(){ | |
System.out.println("Solde : " + this.montant + "€"); | |
} | |
public void deposerArgent(int montant){ | |
this.montant += montant; | |
} | |
public void retirerArgent(int montant){ | |
int montantApresCalcul = this.montant - montant; | |
if(montantApresCalcul >= this.decouvertAutorise){ | |
this.montant -= montant; | |
}else{ | |
System.out.println("Vous n'avez pas les fonds !"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
// afficher un message de bienvenue | |
System.out.println("Bienvenue à la GBA, que souhaitez-vous faire ?"); | |
// créer un objet Comptecourant | |
CompteCourant gravenMoney = new CompteCourant("Graven", 12000); | |
gravenMoney.afficherSolde(); | |
gravenMoney.deposerArgent(300); | |
gravenMoney.afficherSolde(); | |
gravenMoney.retirerArgent(13000); | |
gravenMoney.afficherSolde(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment