Untitled

mail@pastecode.io avatar
unknown
java
a year ago
1.7 kB
2
Indexable
Never
package org.generation;
import java.util.ArrayList;
public class ATM {
          private double balance;
      private int serialNumber;
      private ArrayList<String> log = new ArrayList<String>();
          ATM(double balance, int serialNumber) {
            this.balance = balance;
            this.serialNumber = serialNumber;
       
  }
      public double getBalance() {
            return balance;
       
  }
      public void setBalance(double balance) {
            this.balance = balance;
       
  }
      public int getSerialNumber() {
            return serialNumber;
       
  }
      public void setSerialNumber(int serialNumber) {
            this.serialNumber = serialNumber;
       
  }
          public void deposit(double amount) throws NegativeAmountException {
            if (amount < 0) {
                  throw new NegativeAmountException(
          "La cantidad a depositar es negativa");
             
    }
            log.add("añadiste $" + amount + " a tu cuenta! :D");
            this.balance += amount;
       
  }
          public void withdraw(double amount) throws OverTheBalanceException {
            if (amount > balance) {
                  throw new OverTheBalanceException(
          "La cantidad a retirar excede el saldo de tu cuenta");
             
    }
            log.add("retiraste $" + amount + " de tu cuenta! D:");
            this.balance -= amount;
       
  }
          public void printLog() {
            for (int i = 0; i < log.size(); i++) {
                  System.out.println(log.get(i));
             
    }
       
  }
}