Exercise 4: Creating a Simple Bank Package (Level 3)
In this exercise, you will create a development environment for the Banking project with src and classes directories. You will also place the Account class and TestAccount program into packages. These are the level 3 instructions, which provide additional hints with code snippets.
Preparation
There is no preparation for this exercise.
Task 1 - Creating the Development Directories
Create the development environment directories for the source and class
files as described in "Development" on slide 22 of Module 2.
mkdir src\com\mybank\domain
mkdir src\com\mybank\test
mkdir classes
Task 2 - Modifying the Account
Class
Using a text editor, modify the Account.java
source file and place the class in the appropriate package. Add the
following statement to the top of the Account.java source file:
package com.mybank.domain;
Move the Account.java source file into the appropriate development subdirectory.
move Account.java src\com\mybank\domain
Task 3 - Modifying the TestAccount
Program
Using a text editor, modify the TestAccount.java
source file, place the program in the appropriate package, and include
the appropriate imported classes. Add the following package and import
statements to the top of the TestAccount.java source file:
package com.mybank.test;
import com.mybank.domain.Account;
Move the TestAccount.java source file into the appropriate development subdirectory.
move TestAccount.java src\com\mybank\test
Task 4 - Cleaning Up the Project Directory
Remove all class files and any backup files created by your text editor.
del *.class
Task 5 - Compiling the TestAccount Program
On the command line, use the javac command to compile the test program and the Account class
cd src
javac -d ../classes com/mybank/test/TestAccount.java
.
Task 6 - Running the TestAccount Program
On the command line, use the java command to run the test program.
javac -classpath ../classes com.mybank.test.TestAccount
The code has not changed, so you should still see the following output:
The final balance is 147.0