|
Summary: Simon continues his exploration of the Java language... with sample code.
Into Java, Part II - MyBank.java By: Simon Gronlund
The code of the class MyBank.java which takes use of the class BankAccount.
public class MyBank {
public static void main (String [] args) {
BankAccount john = new BankAccount("John");
BankAccount chris = new BankAccount("Chris", 1000);
System.out.print(john.toString() + ", balance: ");
System.out.println(john.balance());
System.out.print(chris.toString() + ", balance: ");
System.out.println(chris.balance());
john.deposit(500);
System.out.print(john.toString() + ", balance: ");
System.out.println(john.balance());
john.withdraw(600);
john.withdraw(500);
System.out.print(john.toString() + ", balance: ");
System.out.println(john.balance());
chris.name("Chris Wenham");
System.out.print(chris.toString() + ", balance: ");
System.out.println(chris.balance());
System.out.println(chris.name());
BankAccount simon = new BankAccount(125000);
System.out.print(simon.toString() + ", balance: ");
System.out.println(simon.balance());
simon.name("Simon");
System.out.print(simon.toString() + ", balance: ");
System.out.println(simon.balance());
simon.deposit(-1000);
simon.withdraw(-120000);
System.out.print(simon.toString() + ", balance: ");
System.out.println(simon.balance());
}
}
|
|