[JAVA] méthode de transfert
Fermé
John5
-
12 nov. 2007 à 00:13
kij_82 Messages postés 4089 Date d'inscription jeudi 7 avril 2005 Statut Contributeur Dernière intervention 30 septembre 2013 - 12 nov. 2007 à 14:05
kij_82 Messages postés 4089 Date d'inscription jeudi 7 avril 2005 Statut Contributeur Dernière intervention 30 septembre 2013 - 12 nov. 2007 à 14:05
A voir également:
- [JAVA] méthode de transfert
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel football - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Waptrick java voiture - Télécharger - Jeux vidéo
- Java décompiler - Télécharger - Langages
1 réponse
kij_82
Messages postés
4089
Date d'inscription
jeudi 7 avril 2005
Statut
Contributeur
Dernière intervention
30 septembre 2013
857
12 nov. 2007 à 14:05
12 nov. 2007 à 14:05
Salut,
Voilà pour ta classe :
- une méthode pour faire un transfert entre deux comptes => transfert()
-une méthode pour faire un dépôt => depot()
- une méthode pour faire un retrait => retrait()
- une méthode pour connaître le solde => getSolde()
-une redéfinition des méthodes equals et compareTo. => equals() et compareTo()
- une méthode toString => toString()
Il ne te reste plus qu'à faire une méthode main permettant de présenter le fameux menu pour tester les différentes opérations.
Voilà pour ta classe :
public class Compte { /**************************/ /** PROPERTIES **/ /**************************/ /** Numéro du compte **/ private int id = 0; /** Nom du détenteur **/ private String name = null; /** Type du compte (i.e. chèque ou épargne) **/ private String type = null; /** Solde **/ private double solde = 0; /**************************/ /** CONSTRUCTORS **/ /**************************/ /** * Compte * Defaul class constructor * @param theId int * @param theName String * @param theType String */ public Compte ( int theId, String theName, String theType ){ super(); setId(theId); setName(theName); setType(theType); // --- Set default value for property 'solde' setSolde(0); } /**************************/ /** METHODS **/ /**************************/ /** * depot * Increase current balance with new amount * @param theAmount double * @return boolean */ public boolean depot ( double theAmount ){ // --- Test if the amount is a real value and has not a negative value if ( ! Double.isNaN(theAmount) && theAmount > 0 ){ // --- Increase current balance with the amount setSolde( getSolde() + theAmount ); // --- Return TRUE => operation successfull return true; } // --- Return FALSE => operation unsuccessfull return false; } /** * retrait * Withdraw money from current account * @param theAmount double * @return boolean */ public boolean retrait ( double theAmount ){ // --- Test if the amount is a real value and has not a negative value // --- Test if (current balance - amount) is still positive !! if ( ! Double.isNaN(theAmount) && theAmount > 0 && (getSolde()-theAmount) > 0 ){ // --- Do the treatment setSolde( getSolde() - theAmount ); // --- Return TRUE => operation successfull } // --- Return FALSE => operation unsuccessfull return false; } /** * toString * Get a string description of the account * @return String */ public String toString ( ){ return String.valueOf(getId()).concat(" - ").concat(getType()).concat(" - ").concat(getName()).concat(" - Montant : ").concat(String.valueOf(getSolde())); } /** * transfert * Transfert the amount from theAccount to current account * @param TheAccountFrom Compte * @param theAmount double * @return boolean */ public boolean transfert ( Compte TheAccountFrom, double theAmount ){ // --- Do the transfert only if the account from exists (not null) and if it contain the amount to decrease and add to current account if ( TheAccountFrom != null && TheAccountFrom.retrait(theAmount) ){ // --- Add the amount to current account depot(theAmount); // --- Return TRUE => operation successfull return true; } // --- Return FALSE => operation unsuccessfull return false; } /** * equals * Check if current balance is equals to the amount * @param theAmount double * @return boolean */ public boolean equals ( double theAmount ){ return theAmount == getSolde(); } /** * compareTo * Compare current balance with the amount * @param theAmount double * @return int */ public int compareTo ( double theAmount ){ if ( getSolde() > theAmount ) return 1; else if ( getSolde() == theAmount ) return 0; else return -1; } /**************************/ /** GETTERS & SETTERS **/ /**************************/ /** * setId * Set id value * @param theId int */ public void setId ( int theId ){ this.id = theId; } /** * getId * Get id value * @return int */ public int getId ( ){ return this.id; } /** * setName * Set name value * @param theName String */ public void setName ( String theName ){ this.name = theName; } /** * getName * Get name value * @return String */ public String getName ( ){ return this.name; } /** * setSolde * Set solde value * @param theSolde String */ private void setSolde ( double theSolde ){ this.solde = theSolde; } /** * getSolde * Get solde value * @return double */ public double getSolde ( ){ return this.solde; } /** * setType * Set type value * @param theType String */ public void setType ( String theType ){ this.type = theType; } /** * getType * Get type value * @return String */ public String getType ( ){ return this.type; } }
- une méthode pour faire un transfert entre deux comptes => transfert()
-une méthode pour faire un dépôt => depot()
- une méthode pour faire un retrait => retrait()
- une méthode pour connaître le solde => getSolde()
-une redéfinition des méthodes equals et compareTo. => equals() et compareTo()
- une méthode toString => toString()
Il ne te reste plus qu'à faire une méthode main permettant de présenter le fameux menu pour tester les différentes opérations.