Guest User

Untitled

a guest
Jan 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. package iut.portemonnaie;
  2.  
  3. public class Argent {
  4.     private String devise;
  5.     private float montant;
  6.  
  7.     public Argent(float montant, String devise) throws SoldeNegatifException{
  8.         if (montant < 0)
  9.             throw new SoldeNegatifException();
  10.         else {
  11.             this.montant = montant;
  12.             this.devise = devise;
  13.         }
  14.     }
  15.  
  16.     public float getMontant() {
  17.         return montant;
  18.     }
  19.  
  20.     public void setMontant(float montant) {
  21.         this.montant = montant;
  22.     }
  23.  
  24.     public String getDevise() {
  25.         return devise;
  26.     }
  27.  
  28.     public void setDevise(String devise) {
  29.         this.devise = devise;
  30.     }
  31.  
  32.     public void ajouter(Argent a) throws DeviseDifferenceException {
  33.         if (getDevise().equals(a.getDevise()))
  34.             throw new DeviseDifferenceException();
  35.         else
  36.             setMontant(a.getMontant() + getMontant());
  37.     }
  38.  
  39.     public void retirer(Argent a) throws DeviseDifferenceException, SoldeNegatifException {
  40.         if (getDevise().equals(a.getDevise()))
  41.             throw new DeviseDifferenceException();
  42.         else if ((getMontant() - a.getMontant()) < 0)
  43.             throw new SoldeNegatifException();
  44.         else
  45.             setMontant(getMontant() - a.getMontant());
  46.     }
  47.  
  48.     public void convertir(String nomDevise, float taux) {
  49.         setMontant(taux*getMontant());
  50.         setDevise(nomDevise);
  51.     }
  52.    
  53.     public boolean equals(Object o) {
  54.         if ((getDevise().equals(((Argent) o).getDevise())) && (getMontant() == ((Argent) o).getMontant())) return true;
  55.         else return false;
  56.        
  57.     }
  58. }
Add Comment
Please, Sign In to add comment