Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package iut.portemonnaie;
- public class Argent {
- private String devise;
- private float montant;
- public Argent(float montant, String devise) throws SoldeNegatifException{
- if (montant < 0)
- throw new SoldeNegatifException();
- else {
- this.montant = montant;
- this.devise = devise;
- }
- }
- public float getMontant() {
- return montant;
- }
- public void setMontant(float montant) {
- this.montant = montant;
- }
- public String getDevise() {
- return devise;
- }
- public void setDevise(String devise) {
- this.devise = devise;
- }
- public void ajouter(Argent a) throws DeviseDifferenceException {
- if (getDevise().equals(a.getDevise()))
- throw new DeviseDifferenceException();
- else
- setMontant(a.getMontant() + getMontant());
- }
- public void retirer(Argent a) throws DeviseDifferenceException, SoldeNegatifException {
- if (getDevise().equals(a.getDevise()))
- throw new DeviseDifferenceException();
- else if ((getMontant() - a.getMontant()) < 0)
- throw new SoldeNegatifException();
- else
- setMontant(getMontant() - a.getMontant());
- }
- public void convertir(String nomDevise, float taux) {
- setMontant(taux*getMontant());
- setDevise(nomDevise);
- }
- public boolean equals(Object o) {
- if ((getDevise().equals(((Argent) o).getDevise())) && (getMontant() == ((Argent) o).getMontant())) return true;
- else return false;
- }
- }
Add Comment
Please, Sign In to add comment