spiny94

Untitled

Sep 13th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. package BankServices;
  2.  
  3. import java.util.Collections;
  4. import java.util.Comparator;
  5. import java.util.LinkedList;
  6. import java.util.List;
  7. import java.util.Iterator;
  8.  
  9. public class Account {
  10. // List<Deposit> deposits = new LinkedList<>();
  11. // List<Withdrawal> withdrawals = new LinkedList<>();
  12.  
  13. List<Operation> movements = new LinkedList<>();
  14. private String name;
  15. private int code;
  16. private int date;
  17. private Withdrawal w;
  18. private double initial;
  19. private double balance;
  20. private double value;
  21. private Deposit d;
  22.  
  23. public Account(int code, String name, int date, double initial) {
  24. this.name = name;
  25. this.date = date;
  26. this.initial = initial;
  27. this.balance = initial;
  28. this.code = code;
  29. }
  30.  
  31. public double getBalance() {
  32. return balance;
  33. }
  34.  
  35. public void addToBalance(int data, double deposit) {
  36. balance += deposit;
  37. Deposit d = new Deposit(data, deposit);
  38. movements.add(d);
  39. }
  40.  
  41. public void subtractFromBalance(int data, double withdrawal) {
  42. balance -= withdrawal;
  43. Withdrawal w = new Withdrawal(data, withdrawal);
  44. movements.add(w);
  45. }
  46.  
  47. /*
  48. * public double getValue() { // TODO Auto-generated method stub return
  49. * value; }
  50. */
  51.  
  52. public String toString() {
  53. // value = initial;
  54. return code + "," + name + "," + date + "," + balance;
  55. }
  56.  
  57. public List<Operation> getMovements() {
  58.  
  59. Collections.sort(movements, new Comparator<Operation>() {
  60. public int compare(Operation a, Operation b) {
  61. return (int) (b.data - a.data);
  62.  
  63. }
  64. });
  65.  
  66. return movements;
  67. }
  68.  
  69. public List<Deposit> getDeposits() {
  70.  
  71. List<Deposit> deposits = new LinkedList<Deposit>();
  72.  
  73. Iterator<Operation> it = movements.iterator();
  74. while (it.hasNext()) {
  75. Operation o = it.next();
  76. if (d instanceof Deposit) {
  77. deposits.add(d);
  78. }
  79. }
  80. Collections.sort(deposits, new Comparator<Deposit>() {
  81. public double compare(Deposit a, Deposit b) { //errore
  82. return (double) (b.getImport() - a.getImport());
  83.  
  84. }
  85. });
  86. return deposits;
  87. }
  88.  
  89. public List<Withdrawal> getWithdrawals() {
  90. List<Withdrawal> withdrawals = new LinkedList<Withdrawal>();
  91. Iterator<Operation> it = movements.iterator();
  92. while (it.hasNext()) {
  93. Operation o = it.next();
  94. if (w instanceof Withdrawal) {
  95. withdrawals.add(w);
  96. }
  97. }
  98.  
  99. Collections.sort(withdrawals, new Comparator<Withdrawal>() {
  100. public double compare(Withdrawal a, Withdrawal b) { //errore
  101. return (double) (b.getImport() - a.getImport());
  102.  
  103. }
  104. });
  105. return withdrawals;
  106. }
  107.  
  108. public double getInitial() {
  109. // TODO Auto-generated method stub
  110. return initial;
  111. }
  112.  
  113. public int getDate() {
  114. // TODO Auto-generated method stub
  115. return date;
  116. }
  117.  
  118. public void setBalance(double balance) {
  119. // TODO Auto-generated method stub
  120. this.balance = balance;
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment