Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. public class MinMaxAccount extends BankingAccount {
  2.     private int balance;
  3.     private int min;
  4.     private int max;
  5.     
  6.     private List<String> historyTransaction;
  7.     private List<String> historyBalance;
  8.     
  9.     public MinMaxAccount(Startup s) {
  10.         super(s);
  11.         this.min = balance;
  12.         this.max = balance;
  13.     }
  14.     
  15.     private String valueToHistory(int value) {
  16.         int absValue = Math.abs(value);
  17.         return (value < 0 ? "(-" : "") + (absValue / 100) + "." + (absValue % 100 / 10) + (absValue % 100 % 10) + (value < 0 ? ")" : " ");
  18.     }
  19.     
  20.     public String toString() {
  21.         int absBalance = Math.abs(balance);
  22.         return (balance < 0 ? "-" : "") + "$" + (absBalance / 100) + "." + (absBalance % 100 / 10) + (absBalance % 100 % 10);
  23.     }
  24.     
  25.     public void debit(Debit d) {
  26.         super.debit(d);
  27.         if (balance < min) {
  28.             min = balance;
  29.         } else if (balance > max) {
  30.             max = balance;
  31.         }
  32.     }
  33.     
  34.     public void credit(Credit c) {
  35.         balance += c.credit_getBalance();
  36.         
  37.         historyTransaction.add(valueToHistory(c.credit_getBalance()));
  38.         historyBalance.add(toString());
  39.         if (balance < min) {
  40.             min = balance;
  41.         } else if (balance > max) {
  42.             max = balance;
  43.         }
  44.     }
  45.     
  46.     public int getMin() {
  47.         return min;
  48.     }
  49.     
  50.     public int getMax() {
  51.         return max;
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement