|
|
|
|
Salut,
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. ~ N'oubliez pas la balise "Résolu" lorsque votre problème est... résolu :) ~ |