J'ai mis la main sur une méthode qui effectue quatre types de transactions bancaires, mais je n'arrive pas à créer un "Main" qui pourrait les tester, c'est-à-dire faire un transfert, un dépôt, un retrait et connaître le solde à l'aide d'un menu. Voici la class que j'ai.
/** 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;
/**
* 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);
}
/**
* 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;
}
/**
* 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
}
/**
* 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;
}
Bah c'est pas bien dur si tu a déjà fait de la POO. Tu n'a juste qu'à créer ta méthode main, ensuite tu te crée un objet Compte (regarde le construteur pour voir les paramètres) et ensuite tu fait l'appel des différents méthodes d'instances. Où est le problème ?
Class Compte
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.