$30
CSIT111/811
Assignment #2
Total Mark: 10
The purpose of this assignment is:
• Arithmetic operators and Math functions
• Classes and Objects
• Class members
• Constructors
Read the assignment specification carefully, and make sure that you follow whatever directed
in this assignment. In every assignment that you will submit in this subject, you must put the
following information in the header of your assignment:
/*------------------------------------------------------
Name:
Student number:
Email address:
Subject Code: CSIT111/811
Assignment number: 2
-------------------------------------------------------*/
Make sure that you include this information in every assignment file, otherwise it will not be
marked
Objective
This assignment requires you to create a program to calculate bank interests.
Upon completion of this assignment, you should be able to create programs using proper data
types, variables, arithmetic expressions and mathematical functions with classes and objects.
Background
You will create a program, named Bank.java, to calculate the final balance of a customer’s
accounts. The final balance of accounts is calculated using the compound interest formula as:
������� = � × [1 + -
�
�
/]
1×2
where P is the principal, r is the annual rate of interest in percentage, n is the number of times
the interest is compounded per year and t is the periods of time over which the interest is
accumulating. In Australia, banks normally publish their interests as annual interests in
percentage and we assume the interests are calculated on the basis of months so that n = 12
which is a constant and t is the period in a number of years. To simplify the calculation, we
only consider the periods as whole years so that t takes integral numbers of years.
Your program will take initial balances for two bank accounts: saving and check accounts,
and number of years for one customer to find out the final balances for the two accounts.
Assume the two accounts have fixed annual rate of interest. The interest rate (r) for saving
account is 2.95 and for check account is 2.1.
CODING REQUIREMENTS
• Your program shall be implemented using materials covered in lectures 1-7.
• You can use the methods predefined in Math class.
• Your program shall be compliable by JDK SE 8
Write a Java program, called Bank.java, to implement three classes as modeled in
following class diagrams exactly. You are NOT allowed to modify the class diagrams.
Bank
-customer:Customer
-numYears:int
-INTERST_SAVING:double {read only}
-INTEREST_CHEQUE:double {read only}
+main(args: String[]):void
+createCustomerAccounts():void
+printInitialBalances():void
+printFinalBalances():void
Customer
-name:String
-savingAccount:Account
-checkAccount:Account
Customer(name:String, savingAccount:Account, checkAccount:Account)
+getSavingAccount():Account
+getCheckAccount():Account
+getCustomerName():String
Account
-balance:double
-NUM_COMPOUND_TIMES:int {read only}
Account(balance:double)
+getInitialBalance():double
+getFinalBalance(rate:double, numYears:int):double
In this assignment you can presume that the user always inputs correct values (input
verification is not required).
Bank Class:
• Has four data fields to keep the reference of a Customer object, the number of years ,
and the interest rates of two bank accounts;
• In the Main() method, the createCustomerAccounts() method shall be
called firstly to create a Customer object. Then printInitialBalances()
and printInitialBalances() methods shall be called to print the initial and
final balances of the customer’s two accounts by using the Customer object created
above.
• In the createCustomerAccounts() method, the program shall ask the user to
input necessary information (i.e., name, number of years, and initial balances) to
create two Account objects (i.e., the saving and the check accounts), and then
create a Customer object with the two Account objects and the customer’s name.
• The printInitialBalances() and printFinalBalances() methods
shall print out the initial and final balances of the two accounts by using the
Customer object. Please check the output format request at the end of the example
given below.
Customer Class:
• Has three data fields to keep the customer’s name, and two references of Account
objects (i.e., the saving and the check accounts);
• The constructor method Customer() shall be used to create a Customer object
with three arguments;
• The getSavingAccount()and getCheckAccount() methods shall return
the two Account references of the customer, respectively;
• The getCustomerName()method shall return the customer’s name;
Account Class:
• Has two data fields to keep the initial balance, and the compound times (i.e., the fixed
whole number 12) of the account;
• The constructor method Account() shall be used to create an Account() object
with one argument;
• The getInitialBalance() method shall return the initial balance of the
account;
• The getFinalBalance(rate:double,numYears:int) method shall
calculate the final balance according to the formula given above with two arguments
and return the final balance of the account.
An example of a test case is shown below (the user’s inputs are highlighted by the blue colour).
However, you shall test your program with other test cases before you submit it to make sure
it meets all design requirements.
Example of the program output:
Enter the customer’s full name: John
Enter the number of years: 4
Enter initial balance for the saving account: 10000.05
Enter initial balance for the check account: 20000
==========================================
Initial account balances
==========================================
John’s Account Rate Balance
==========================================
Saving 2.95% $10000.05
Check 2.10% $20000.00
==========================================
==========================================
Final account balances after 4 years
==========================================
John’s Account Rate Balance
==========================================
Saving 2.95% $11250.87
Check 2.10% $21750.98
==========================================
Output format request:
• using the printf() method to print the outputs;
• using two tabs between texts “John’s Account” and “Rate”, one tab between texts
“Rate” and “Balance”;
• using three tabs between the text “Saving/Check” and the actual rates, one tab
between the actual rates and the actual balances;
• adding the ‘%’ signs after the actual rates;
• adding the ‘$’ sign before the actual balances;
• The actual balances shall be displayed as dollars and cents, such as $11.25.
Submission:
Submit your single Java program to Moodle “Assignment 2”
- The submitted file name must be Bank.java. Files with other names will not
be tested and marked.
- Submit your assignment before the due date. You can freely update your
submission before the due date.
- Submission via email is NOT acceptable.
- Enquiries about the marks can only be made within a maximum of 1 week after
the assignment results are published. After 1 week the marks cannot be
changed.
Mark deductions: compilation errors, incorrect result, program is not up to spec, poor
comments, poor indentation, meaningless identifiers, required numeric constants are not
defined, the program uses approaches which has not been covered in the lectures. The
deductions here are merely a guide. Marks may also be deducted for other mistakes and
poor practices.