Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WILL UPVOTE! From Assignment 4 , the Account class was defined to model a bank account. An account has the properties account number, balance, annual

  • WILL UPVOTE!
  • From Assignment 4, the Account class was defined to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds.
  • Create one subclass as CDAccount. You will add two private variables, duration (in months) and CDannualInterestRate, and their getter and setter member functions.
  • A CDAccount doesnt allow any deposit or withdraw. However, CDAccount does inheritance deposit and withdraw methods from the Account class. So you need to override these two methods as final methods, and print out a message to the console about no withdraw or deposit allowed for a CDAccount. ( See the sample output for example.)
  • Include getMatureBalance() method to get the end balance at the mature date of the CDAccount.

    matureBalance = (balance) * (1 + CDmonthlyInterestRate)duration

  • Include toString() method to print the account ID, CD annual interest rate, the initial balance, the mature balance, and the date when this account was created. (Refer to the sample output).

** Remember the return type of the toString() method is String. To print out a formatted output from the toString() method, you can use String.format(). Also you always can concatenate two Strings with the "+" operator.

  • Include displayMonthlyInterests() method to print each monthly balance (initial balance + monthly interest) during the CD duration.

** You need to write a for-loop and apply the formula of calculating the mature balance, but replace the duration with the number of months.

  • CDAccount constructor function will call the private method, setCDAnnualInterestRate(), to set up the CD Annual Interest Rate: Every three months CD duration will increase the CDannualInterestRate by 0.5% from annualInterestRate of the base class. For example: if annualInterestRate is 3%, the CDannualInterestRate will be 3.5% of a three-months CD saving account, and the CDannualInterestRate will be 4% of a six-month CD.

** Pay attention in the UML diagram, there is no parameter in the setCDAnnualInterestRate(). You only need to call Account.getAnnualInterestRate() to get the annual interest rate as the base, then add each half percent for every three months duration.

  • Write a driver program (Assignment6.java) to test class CDAccount. Create an array contains five objects of class CDAccount with balances of $1000.00 to $5000.00, and duration from 3-month to 15-months respectively. Set the annualInterestRate to 3%. Display each account information, and print the monthly interest of every month during the saving period for each CDAccount.

  • Perform deposit and withdraw actions on each CDAccount. ( A error message will be displayed to the console to indicate the deposit and withdraw actions are not allowed.)

  • Comment your name and ID in the first line of each source file.

Code from assignment 4

import java.util.Date;

public class Account {

private int id;

private double balance;

private static double annualInterestRate;

private Date date;

public Account() {

this.id = 0;

this.balance = 0;

this.annualInterestRate = 0;

this.date = new Date();

}

public Account(int id, double initialBal) {

this.id = id;

this.balance = initialBal;

this.annualInterestRate = 0;

this.date = 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 static double getAnnualInterestRate() {

return annualInterestRate;

}

public static void setAnnualInterestRate(double annualInterestRate) {

Account.annualInterestRate = annualInterestRate;

}

public double getMonthlyInterest() {

return balance * (annualInterestRate/1200);

}

public void withdraw(double amt) {

if (amt

balance -= amt;

} else {

System.out.println("** Account balance is low **");

}

}

public void deposit(double amt) {

balance += amt;

}

@Override

public String toString() {

System.out.println(" Account ID:" + id);

System.out.println("Balance:" + balance);

System.out.println("Monthly Interest:" + getMonthlyInterest());

System.out.println("Date Created:" + date);

return "";

}

}

image text in transcribed
image text in transcribed
Sample output, cterminated > Lab Exercise_2 (Java Application/Library/Java/JavaVirtual Machines/jdk1.8.0.101.jdk/Contents/H Account Number Initial Balance Matural Balance Rate(%) 1000 1000.00 1008.78 3.50 Mon Feb Month 1 1002.92 Month 2 1005.84 Month 3 1088.78 A CD Account can't withdraw any cash. You need to close this CD account. A CD Account can't make any additional deposit. You may open another CD account. Account Number Initial Balance Matural Balance Rate(%) 2000 2000.00 2840.33 4.00 Mon Feb Month 1 2006.67 Month 2 2013.36 Month 3 2020.07 Month 4 2026.80 Month 5 2033.56 Month 6 2840.33 A CD Account can't withdraw any cash. You need to close this CD account. A CD Account can't make any additional deposit. You may open another CD account. Account Number Initial Balance Matural Balance Rate(%) 3000 3000.00 3102.78 4.50 Mon Feb Month 1 3011.25 Month 2 3822.54 Month 3 3033.88 Month 4 3845.25 Month 5 3056.67 Month 6 3068.14 Month 7 3879.64 Month 8 3091.19 Month 9 3102.78 A CD Account can't withdraw any cash. You need to close this CD account. A CD Account can't make any additional deposit. You may open another CD account. Month 9 3102.78 A CD Account can't withdraw any cash. You need to close this CD account. A CD Account can't make any additional deposit. You may open another CD account. Account Number Initial Balance Matural Balance Rate(%) 4000 4000.00 4204.65 5.00 Mon Feb Month 1 4016.67 Month 2 4033.40 Month 3 4050.21 Month 4 4067.08 Month 5 4084.03 Month 6 4101.05 Month 7 4118.14 Month 8 4135.29 Month 9 4152.52 Month 10 4169.83 Month 11 4187.20 Month 12 4204.65 A CD Account can't withdraw any cash. You need to close this CD account. A CD Account can't make any additional deposit. You may open another CD account. Account Number Initial Balance Matural Balance Rate(s) 5000 5000.00 5355.00 5.50 Mon Feb Month 1 5822.92 Month 2 5845.94 Month 3 5069.07 Month 4 5092.30 Month 5 5115.64 Month 6 5139.99 Month 7 5162.64 Month 8 5186.38 Month 9 5210.07 Month 10 5233.95 Month 11 5257.94 Month 12 5282.84 Month 13 5386.25 Month 14 5330.57 Month 15 5355.00 A CD Account can't withdraw any cash. You need to close this CD account. A CD Account can't make any additional deposit. You may open another CD account. Submit your source codes Account Lava CDAcountiava and Assignment laval pocted package "Module" Writable Smart Insert

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

9. Assess the validity of a coding scheme.

Answered: 1 week ago