spiny94

Untitled

Sep 12th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. public void withdraw(int code, int date, double value) throws InvalidCode,
  2. InvalidValue {
  3. if (!accounts.containsKey(code)) {
  4. throw new InvalidCode();
  5. }
  6. // if (value < accounts.get(code).getValue())
  7. if (value > accounts.get(code).getBalance()) {
  8. throw new InvalidValue();
  9. } else {
  10.  
  11. // prelievi.add(accounts.get(code).getValue() - value);
  12. // prelievi.add(accounts.get(code).getBalance() - value);
  13. //double t = accounts.get(code).getBalance() - value;
  14. accounts.get(code).subtractFromBalance(value);
  15. if (date < accounts.get(code).getDate()) {
  16. date = accounts.get(code).getDate();
  17.  
  18. }
  19. }
  20. }
  21.  
  22.  
  23. public void transfer(int fromCode, int toCode, int date, double value)
  24. throws InvalidCode, InvalidValue {
  25. if (!accounts.containsKey(fromCode) || !accounts.containsKey(toCode)) {
  26. throw new InvalidCode();
  27. }
  28. // double s = accounts.get(fromCode).getValue();
  29. //double s = accounts.get(fromCode).getBalance();
  30. // if (s > accounts.get(toCode).getValue()) {
  31.  
  32. //if (value > s) {
  33. if ( value> accounts.get(fromCode).getBalance()){
  34. throw new InvalidValue();
  35. } else {
  36. // double t = accounts.get(toCode).getValue();
  37. //double t = accounts.get(toCode).getBalance();
  38. //double t;
  39. //t = s- value;
  40. accounts.get(fromCode).subtractFromBalance(value);
  41. accounts.get(toCode).addToBalance(value);
  42. //t += s;
  43.  
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment