Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package BankServices;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Iterator;
- public class Account {
- // List<Deposit> deposits = new LinkedList<>();
- // List<Withdrawal> withdrawals = new LinkedList<>();
- List<Operation> movements = new LinkedList<>();
- private String name;
- private int code;
- private int date;
- private Withdrawal w;
- private double initial;
- private double balance;
- private double value;
- private Deposit d;
- public Account(int code, String name, int date, double initial) {
- this.name = name;
- this.date = date;
- this.initial = initial;
- this.balance = initial;
- this.code = code;
- }
- public double getBalance() {
- return balance;
- }
- public void addToBalance(int data, double deposit) {
- balance += deposit;
- Deposit d = new Deposit(data, deposit);
- movements.add(d);
- //deposits.add(d);
- }
- public void subtractFromBalance(int data, double withdrawal) {
- balance -= withdrawal;
- Withdrawal w = new Withdrawal(data, withdrawal);
- movements.add(w);
- }
- /*
- * public double getValue() { // TODO Auto-generated method stub return
- * value; }
- */
- public String toString() {
- // value = initial;
- return code + "," + name + "," + date + "," + balance;
- }
- public List<Operation> getMovements() {
- Collections.sort(movements, new Comparator<Operation>() {
- public int compare(Operation a, Operation b) {
- return (int)(b.data - a.data);
- }
- });
- return movements;
- }
- public List<Deposit> getDeposits() {
- List<Deposit> deposits = new LinkedList<Deposit>();
- Iterator<Operation> it = movements.iterator();
- while (it.hasNext()) {
- Operation o = it.next();
- if ( o instanceof Deposit) {
- deposits.add((Deposit)o);
- }
- }
- Collections.sort(deposits, new Comparator<Deposit>() {
- public int compare(Deposit a, Deposit b) { //errore
- return (int) (b.getImport() - a.getImport());
- }
- });
- return deposits;
- }
- public List<Withdrawal> getWithdrawals() {
- List<Withdrawal> withdrawals = new LinkedList<Withdrawal>();
- Iterator<Operation> it = movements.iterator();
- while (it.hasNext()) {
- Operation o = it.next();
- if (o instanceof Withdrawal) {
- withdrawals.add((Withdrawal)o);
- }
- }
- Collections.sort(withdrawals, new Comparator<Withdrawal>() {
- public int compare(Withdrawal a, Withdrawal b) { //errore
- return (int) (b.getImport() - a.getImport());
- }
- });
- return withdrawals;
- }
- public double getInitial() {
- // TODO Auto-generated method stub
- return initial;
- }
- public int getDate() {
- // TODO Auto-generated method stub
- return date;
- }
- public void setBalance(double balance) {
- // TODO Auto-generated method stub
- this.balance = balance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement