Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MinMaxAccount extends BankingAccount {
- private int balance;
- private int min;
- private int max;
- private List<String> historyTransaction;
- private List<String> historyBalance;
- public MinMaxAccount(Startup s) {
- super(s);
- this.min = balance;
- this.max = balance;
- }
- private String valueToHistory(int value) {
- int absValue = Math.abs(value);
- return (value < 0 ? "(-" : "") + (absValue / 100) + "." + (absValue % 100 / 10) + (absValue % 100 % 10) + (value < 0 ? ")" : " ");
- }
- public String toString() {
- int absBalance = Math.abs(balance);
- return (balance < 0 ? "-" : "") + "$" + (absBalance / 100) + "." + (absBalance % 100 / 10) + (absBalance % 100 % 10);
- }
- public void debit(Debit d) {
- super.debit(d);
- if (balance < min) {
- min = balance;
- } else if (balance > max) {
- max = balance;
- }
- }
- public void credit(Credit c) {
- balance += c.credit_getBalance();
- historyTransaction.add(valueToHistory(c.credit_getBalance()));
- historyBalance.add(toString());
- if (balance < min) {
- min = balance;
- } else if (balance > max) {
- max = balance;
- }
- }
- public int getMin() {
- return min;
- }
- public int getMax() {
- return max;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement