Partage
  • Partager sur Facebook
  • Partager sur Twitter

Class Compte

Main

    7 novembre 2008 à 4:31:26

    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.

    Merci à l'avance.

    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;
    }

    }



    • Partager sur Facebook
    • Partager sur Twitter
      7 novembre 2008 à 7:05:59

      Hem,utilise les balises de code !
      • Partager sur Facebook
      • Partager sur Twitter
        7 novembre 2008 à 18:28:27

        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 ?
        • Partager sur Facebook
        • Partager sur Twitter

        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.
        • Editeur
        • Markdown