next up previous
Next: Precision in the representation: Up: Unit 04 Previous: Exercise: the class BankAccount

Solution for the class BankAccount

public class BankAccount {
  private String name, surname;
  private double balance;

  public BankAccount(String n, String s) {
    name = n;  surname = s;  balance = 0;
  }

  public void deposit(double val) {
    balance = balance + val;
  }

  public void withdraw(double val) {
    balance = balance - val;
  }

  public String toString() {
    return "{ Owner: " + name + " " + surname +
      " - Balance: Euro " + balance + " }";
  }
}


next up previous
Next: Precision in the representation: Up: Unit 04 Previous: Exercise: the class BankAccount