|
CPT 388 - Java IISpring 2001 |
To learn how to create object-oriented programs using BlueJ.
BlueJ is a Freeware tool created to assist students with learning Object-Oriented programming using Java. It can be downloaded from http://www.bluej.org.
To access BlueJ in the CNC labs, copy the batch file below into your working directory.
g:\pool\tprice\cpt388\bluej.bat
You can start BlueJ by running this batch file.
Create an application that consists of three classes: BankAccount, CheckingAccount, and MyAccount. The properties for these classes are shown below:
public abstract class BankAccount // instance variables private double balance; private String lastName; private String firstName; public BankAccount(String fname, String lname) // constructor public void makeDeposit(double d) public void debit(double d) public double getBalance() public String toString()
public class CheckingAccount extends BankAccount private int accountNumber; // instance variable public CheckingAccount(String fname, String lname, int accountNumber, double deposit) // constructor public void makeDeposit(double d) public void processCheck(int checkNum, double d)
// the complete implementation of MyAccount is shown below
public class MyAccount
{
public static void main(String[] args)
{
CheckingAccount c = new CheckingAccount("Tim", "Price", 22112, 100.0);
System.out.println("Checking acount info: "+c);
c.makeDeposit(200.0);
System.out.println("Checking acount info: "+c);
c.processCheck(1101, 50.0);
System.out.println("Checking acount info: "+c);
}
}
Running the program should generate the output shown below:
$100.0 deposited to account. Checking acount info: Customer: Tim Price Balance: 100.0 $200.0 deposited to account. Checking acount info: Customer: Tim Price Balance: 300.0 Check number 1101 processed for $50.0 Checking acount info: Customer: Tim Price Balance: 250.0
The class diagram in BlueJ is shown below:

Compile and run this program in BlueJ and make sure that the output is correct. Set a breakpoint in main() and single-step your program.
Comments to Course
Coordinator: Prof. Tim Price
All contents copyright
(c)1998 - 2001 Timothy W. Price. All rights reserved.