Advertisement
spiny94

Untitled

Sep 14th, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 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. //deposits.add(d);
  40. }
  41.  
  42. public void subtractFromBalance(int data, double withdrawal) {
  43. balance -= withdrawal;
  44. Withdrawal w = new Withdrawal(data, withdrawal);
  45. movements.add(w);
  46. }
  47.  
  48. /*
  49. * public double getValue() { // TODO Auto-generated method stub return
  50. * value; }
  51. */
  52.  
  53. public String toString() {
  54. // value = initial;
  55. return code + "," + name + "," + date + "," + balance;
  56. }
  57.  
  58. public List<Operation> getMovements() {
  59.  
  60. Collections.sort(movements, new Comparator<Operation>() {
  61. public int compare(Operation a, Operation b) {
  62. return (int)(b.data - a.data);
  63.  
  64. }
  65. });
  66.  
  67. return movements;
  68. }
  69.  
  70. public List<Deposit> getDeposits() {
  71.  
  72. List<Deposit> deposits = new LinkedList<Deposit>();
  73.  
  74. Iterator<Operation> it = movements.iterator();
  75. while (it.hasNext()) {
  76. Operation o = it.next();
  77. if ( o instanceof Deposit) {
  78. deposits.add((Deposit)o);
  79.  
  80. }
  81. }
  82. Collections.sort(deposits, new Comparator<Deposit>() {
  83. public int compare(Deposit a, Deposit b) { //errore
  84. return (int) (b.getImport() - a.getImport());
  85.  
  86. }
  87. });
  88. return deposits;
  89. }
  90.  
  91. public List<Withdrawal> getWithdrawals() {
  92. List<Withdrawal> withdrawals = new LinkedList<Withdrawal>();
  93. Iterator<Operation> it = movements.iterator();
  94. while (it.hasNext()) {
  95. Operation o = it.next();
  96. if (o instanceof Withdrawal) {
  97. withdrawals.add((Withdrawal)o);
  98. }
  99. }
  100.  
  101. Collections.sort(withdrawals, new Comparator<Withdrawal>() {
  102. public int compare(Withdrawal a, Withdrawal b) { //errore
  103. return (int) (b.getImport() - a.getImport());
  104.  
  105. }
  106. });
  107. return withdrawals;
  108. }
  109.  
  110. public double getInitial() {
  111. // TODO Auto-generated method stub
  112. return initial;
  113. }
  114.  
  115. public int getDate() {
  116. // TODO Auto-generated method stub
  117. return date;
  118. }
  119.  
  120. public void setBalance(double balance) {
  121. // TODO Auto-generated method stub
  122. this.balance = balance;
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement