[Previous]
Into Java, Part II - MyBank.java - by Simon Gronlund
[Next]
OS/2 e-Zine!

Go to a Printer Friendly version of this page



Lash Back! - Join in the ongoing public discussion with our interactive forum. Be frank, be vicious, you can even be anonymous.

- or -

Blast Back! Send a private message directly to Simon Gronlund with your thoughts:

Contact OS/2 e-Zine!

Sponsored links:

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());
    }
}

[Previous]
 [Index]
 [Feedback]
 [Next]
Copyright © 1999 - Falcon Networking ISSN 1203-5696
November 1, 1999