Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Description:
(The Account class)
Design a class named Account that contains:
A private int data field named id for the account (default 0).
A private double data field named balance for the account (default 0).
A private double data field named annualInterestRate that stores the current
interest rate (default 0). Assume all accounts have the same interest rate.
A private Date data field named dateCreated that stores the date when the
account was created.
A no-arg constructor that creates a default account.
A constructor that creates an account with the specified id and initial balance.
The accessor and mutator methods for id, balance, and annualInterestRate.
The accessor method for dateCreated.
A method named getMonthlyInterestRate() that returns the monthly interest
rate.
A method named getMonthlyInterest() that returns the monthly interest.
A method named withdraw that withdraws a specified amount from the
account.
A method named deposit that deposits a specified amount to the account.
Draw the UML diagram for the class and then implement the class. (Hint: The
method getMonthlyInterest() is to return monthly interest, not the interest rate.
Monthly interest is balance * monthlyInterestRate. monthlyInterestRate is
annualInterestRate / 12. Note that annualInterestRate is a percentage, e.g.,like
3%. You need to divide it by 100.)
Write a test program that creates an Account object array of size 5. The account
IDs are 1000 to 5000, balance of $1,000 to 5000, and an annual interest rate of
3%. Use the withdraw method to withdraw $500, use the deposit method to
deposit $1000, and print the balance, the monthly interest, and the date when
this account was created for each account.
Submit your source code,UML diagram and screenshots in one WORD document
or zip file (if more files included) at Week 4 Assignment from course portal by
11:30pm the next class day.
UML Diagram:
package HW5;
import java.util.*;
public class Account
{
private int id;
private double balance;
private double annualInterestRate;
private Date dateCreated;
public Account()
{
id=123131;
}
public Account(int id, double balance)
{
this.id=id;
this.balance=balance;
dateCreated=new Date();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
package HW5;
public class TestAccount {
public static void main(String[] args) {
System.out
.println("Account Number\t Balance\t Monthly Interest\t Created Date ");
Account[] account = new Account[5];
for (int i = 0; i < account.length; i++) {
account[i] = new Account((i + 1) * 1000, (i + 1) * 1000);
Output:
Account Number
Balance
Monthly Interest
Created Date
1000.0
2.5
2000
2000.0
5.0
3000
3000.0
7.5
4000
4000.0
10.0
5000
5000.0
12.5
500.0 1.25
1500.0 3.75
2500.0 6.25
3500.0 8.75
1500.0 3.75
2500.0 6.25
3500.0 8.75