Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void withdraw(int code, int date, double value) throws InvalidCode,
- InvalidValue {
- if (!accounts.containsKey(code)) {
- throw new InvalidCode();
- }
- // if (value < accounts.get(code).getValue())
- if (value > accounts.get(code).getBalance()) {
- throw new InvalidValue();
- } else {
- // prelievi.add(accounts.get(code).getValue() - value);
- // prelievi.add(accounts.get(code).getBalance() - value);
- //double t = accounts.get(code).getBalance() - value;
- accounts.get(code).subtractFromBalance(value);
- if (date < accounts.get(code).getDate()) {
- date = accounts.get(code).getDate();
- }
- }
- }
- public void transfer(int fromCode, int toCode, int date, double value)
- throws InvalidCode, InvalidValue {
- if (!accounts.containsKey(fromCode) || !accounts.containsKey(toCode)) {
- throw new InvalidCode();
- }
- // double s = accounts.get(fromCode).getValue();
- //double s = accounts.get(fromCode).getBalance();
- // if (s > accounts.get(toCode).getValue()) {
- //if (value > s) {
- if ( value> accounts.get(fromCode).getBalance()){
- throw new InvalidValue();
- } else {
- // double t = accounts.get(toCode).getValue();
- //double t = accounts.get(toCode).getBalance();
- //double t;
- //t = s- value;
- accounts.get(fromCode).subtractFromBalance(value);
- accounts.get(toCode).addToBalance(value);
- //t += s;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment