Samorokimetal

HW 29/10/20 - BankAccount

Oct 29th, 2020
942
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class BankAccount {
  2.     private int ID;
  3.     private double balance;
  4.  
  5.     public BankAccount(int ID, double balance) {
  6.         this.setID(ID);
  7.         this.setBalance(balance);
  8.     }
  9.  
  10.     public int getID() {
  11.         return ID;
  12.     }
  13.  
  14.     public void setID(int ID) {
  15.         this.ID = ID;
  16.     }
  17.  
  18.     public double getBalance() {
  19.         return balance;
  20.     }
  21.  
  22.     public void setBalance(double balance) {
  23.         if(balance > 0){
  24.             this.balance = balance;
  25.         }
  26.     }
  27.  
  28.     public void Deposit(double amount){
  29.         this.balance += amount;
  30.     }
  31.  
  32.     public void Withdraw(double amount){
  33.         if(this.balance >= amount){
  34.             this.balance -= amount;
  35.         }else {
  36.             System.out.println("No money");
  37.         }
  38.     }
  39.  
  40.     @Override
  41.     public String toString() {
  42.         return "[Account: " + this.ID + ", balance: " + this.balance + "]";
  43.     }
  44. }
RAW Paste Data