Advertisement
aridokmecian

Untitled

Apr 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. package eecs1022.lab5;
  2.  
  3. /**
  4.  * Created by user on 3/14/18.
  5.  */
  6. public class Client {
  7.     public String name;
  8.     public double balance;
  9.     Transaction[] history = new Transaction[10];
  10.     int not = 0; // number of transactions
  11.  
  12.     //Client Constructor
  13.     public Client(String name, double balance){
  14.         this.name = name;
  15.         this.balance = balance;
  16.     }
  17.  
  18.     //Deposits a set amount of money into the balance
  19.     public void deposit(double amount){
  20.         balance = balance + amount;
  21.         history[not] = new Transaction("Deposit", amount);
  22.         not++;
  23.     }
  24.  
  25.     //Withdraws a set amount of money into the balance
  26.     public void withdraw(double amount){
  27.         balance = balance - amount;
  28.         history[not] = new Transaction("Withdraw", amount);
  29.         not++;
  30.     }
  31.     //Method that gets the history of the specific client
  32.     public String getHistory(){
  33.         String s = "";
  34.         for(int i = 0; i < not; i++){
  35.             s += history[i].toString() + "\n";
  36.         }
  37.  
  38.         return s;
  39.     }
  40.  
  41.     //toString Method
  42.     @Override
  43.     public String toString()
  44.     {
  45.         String s = "Statement of Client " + name + " (current balance $"+ String.format("%.2f", balance) + "):" + "\n";
  46.         s += getHistory();
  47.         return s;
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement