Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Perform the following tasks In the driving program, Create an Account array to store 10 Account or CDAccount objects randomly . (accountID from 1001~ 1010,

Perform the following tasks In the driving program,

  1. Create an Account array to store 10 Account or CDAccount objects randomly.

(accountID from 1001~ 1010, and generate the initial balance and CDAccount duration randomly)

2. Use a for-loop to invoke toString() method through the Account object reference to display account information. After withdraw $500 and deposit $1000 on each account, display the account information again.

3. The toString() method in the Account objects, returns a string of the account number and balance; for CDAccount objects, returns a string of the account number, initial balance, duration, mature balance, and Date created.

Modify the toString() methods in the Account class, and CDAccount class if necessary.

//Account Class

package Module4;

import java.util.Date;

public class Account {

private int id = 0;

private double balance = 0;

private double annualInterestRate = 0;

private Date dateCreated = new Date();

// constructor with all parameters

public Account(int id, double balance, double annualInterestRate, Date dateCreated) {

this.id = id;

this.balance = balance;

this.annualInterestRate = annualInterestRate;

this.dateCreated = dateCreated;

}

// default constructor

public Account() {

}

// getter and setter methods

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;

}

public Date getDateCreated() {

return dateCreated;

}

public void setDateCreated(Date dateCreated) {

this.dateCreated = dateCreated;

}

// calculate monthly interest rate

public double getMonthlyInterestRate() {

return Math.round(((this.annualInterestRate / 12) * 100.0) / 100.0);

}

// calculate monthly interest

public double getMonthlyInterest() {

return (balance * this.getAnnualInterestRate()) / 100;

}

// withdraw amount if amount is less then balance

public void withdraw(double amount) {

if (amount

this.setBalance(balance - amount);

}

}

// deposit account if amount > 0

public void deposit(double amount) {

if (amount > 0) {

this.setBalance(balance + amount);

}

}

}

//CDAccount

package Module4;

import java.lang.Math;

import java.util.Date;

public class CDAccount extends Account {

private int duration;

private double CDannualInterestRate;

CDAccount(){

}

CDAccount(int id,double balance,int duration){

super.setId(id);

super.setBalance(balance);

this.duration = duration;

super.setDateCreated(new Date());

super.setAnnualInterestRate(5.50);

}

public void setDuration(int duration) {

this.duration = duration;

}

public int getDuration() {

return this.duration;

}

public double getMatureBalance() {

double matureBalance = 0;

matureBalance = super.getBalance() * Math.pow((1+super.getMonthlyInterestRate()),this.duration);

return matureBalance;

}

public void setCDAnnualInterestRate(double CDannualInterestRate) {

this.CDannualInterestRate = CDannualInterestRate;

}

public double getCDAnnualInterestRate() {

return super.getAnnualInterestRate();

}

public double getMonthlyInterestRate() {

return super.getMonthlyInterestRate();

}

public double getMonthlyInterest() {

return super.getMonthlyInterest();

}

public final void withdraw(double num) {

System.out.println("A CD Account can't withdraw any cash. You need to close this CD account.");

}

public final void deposit(double num) {

System.out.println("A CD Account can't make any additional deposit. You may open another CD account.");

}

public String toString() {

String res = String.format("%2s%25.2f%20.2f%16.2f%5s%20s", super.getId(), super.getBalance(),

this.getMatureBalance(), this.getAnnualInterestRate(), "",

this.getDateCreated());

System.out.format(res);

System.out.println();

return res;

}

public void displayMonthlyinterests() {

System.out.println();

for(int i=0;i

String res = String.format("%2s%25.2f", "Month "+Integer.toString((i+1)), (this.getBalance() + this.getMonthlyInterest()*(i+1)));

System.out.println(res);

}

}

}

Sample output image text in transcribed
LabExercise (Java Application/Library/Java/JavaVirtual Machines/jck1.8.0_181.dk/Contents/Home/bin/java (Oct 1, 2018, 1:49:54 PM Account id: 1801 Account balance: $7990.0 Account id: 1001 Account balance: $7580.0 Account id: 1002 Account balance: $7000. Account id: 1002 Account balance: $7500. Account id: 1003 Account balance: $6000.0 Account id: 1993 Account balance: $6500. Account Number Initial Balance Duration Natural Balance Rate(%) Date Created 1894 5000.00 3 5043.88 3.50 Mon Oct 01 13:49:55 PDT 2018 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 Duration Matural Balance Rate() 1094 5000.00 3 5043.88 3.50 Account Number Initial Balance Duration Date Created Mon Oct 01 13:49:55 PDT 2018 Date Created Mon Oct 01 13:49:55 POT 2018 Matural Balance Rate(%) 1005 3000.ea 3 3026.33 3.50 Date Created Mon Oct 01 13:49:55 POT 2018 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 Duration Matural Balance Rate(%) 1805 3800.00 3026.33 3.50 Account Number Initial Balance Duratton Matural Balance Rotex 1806 3800.00 7 3070.70 4.09 A CO 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 Duration Matural Balance Rates 1986 3000.00 3070.70 4.00 Date Created Mon Oct 01 13:49:55 POT 2018 Date Created Mon Oct 01 13:49:55 PDT 2018 Account id: 1907 Account balance: $4600.0 Account id: 1097 Account balance: $4500. Account Number Initial Balance Duration Matural Balance Rate() Date Created 1008 7000.00 7 7164.98 Mon Oct 01 13:49:55 POT 2018 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 Duration Matural Balance Rate(%) Date Created 7000.00 7 7164.98 1898 Account Number Mon Oct 01 13:49:55 POT 2018 Initial Balance Duration Maturol Balance Date Created 1899 Rate() 3.00 2800.00 2800.00 Mon Oct 01 13:49:55 PDT 2018 A CO Account can't withdrawany cash. You need to close this CD account

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

Recommended Textbook for

Building The Data Lakehouse

Authors: Bill Inmon ,Mary Levins ,Ranjeet Srivastava

1st Edition

1634629663, 978-1634629669

More Books

Students also viewed these Databases questions

Question

Describe how early experiences can modify the brain.

Answered: 1 week ago

Question

Discuss the techniques of job analysis.

Answered: 1 week ago

Question

How do we do subnetting in IPv6?Explain with a suitable example.

Answered: 1 week ago

Question

Explain the guideline for job description.

Answered: 1 week ago

Question

What is job description ? State the uses of job description.

Answered: 1 week ago

Question

What are the objectives of job evaluation ?

Answered: 1 week ago