Chrome File Edit View History Bookmarks People Window Help Lab10 Programming Pri
ID: 3777900 • Letter: C
Question
Chrome File Edit View History Bookmarks People Window Help Lab10 Programming Principle X https:// kennesaw. view.usg.edu d21/le/content/1103674/viewContent/18578408/View?ou 03674 Apps Bookmarks Apple YouTube home Watch Live Sports. Destiny LFG.Ne DestinyTracke De 9.7 CThe 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 annual InterestRate that stores the cur- rent 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. Ano-arg constructor that creates a default account. A constructor that creates an account with the specified id and initial balance. The accessory and mutator methods for id, balance, and annualInterestRate. The accessor method for dateCreated. A method named getMonthlyInterestRateC that returns the monthly interest rate A method named getMonthlyInterestC that returns the monthly interest. A method named withdraw that withdraws a specified amount from t 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 getMonthlyInterestO is to return monthly interest, not the interest rate. Monthly interest is balance monthlyInter monthlyInterestRate is annual InterestRate 12. Note that annualInterestRate is a percentage e.g., like 4.5%. You need to divide it by 100.) Write a test program that creates an Account object with an account ID of 1122, a balance of $20,000, and an annual interest rate of 4.5%. Use the withdraw method to withdraw $2,500,use the deposit method to deposit $3,000, and print the balance, the monthly interest, and the date when this account was created. 10% Sun Nov 27 12:04:37 PM a E Jos Microsoft Device S D Watch Game Thron... Enter an id: 4 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 1. The balance is 100 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 2 Enter an amount to Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 1 The balance is 97 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 3 Enter an amount toExplanation / Answer
import java.util.*;
public class Account{
int id;
double balance;
double annualInterestRate;
Date dateCreated;
public Account(){
this.id = 0;
this.balance = 0;
this.annualInterestRate = 0;
this.dateCreated = new Date();
}
public Account(int id, double balance, double annualInterestRate){
this.id = id;
this.balance = balance;
this.annualInterestRate = annualInterestRate;
}
public int getId(){
return this.id;
}
public double getBalance(){
return this.balance;
}
public double getInterest(){
return this.annualInterestRate;
}
public void setId(int id){
this.id = id;
}
public void setBalance(double balance){
this.balance = balance;
}
public void setInterest(double annualInterestRate){
this.annualInterestRate = annualInterestRate;
}
public Date getDateCreated(){
return this.dateCreated;
}
public double getMonthlyInterestRate(){
return this.annualInterestRate/12.0;
}
public double getMonthlyInterest(){
return getMonthlyInterestRate()*balance/100.0;
}
public void withdraw(double amount){
this.balance -= amount;
}
public void deposit(double amount){
this.balance += amount;
}
public static void main(String[] args) {
Account account = new Account(1122, 20000, 4.5);
account.withdraw(2500);
account.deposit(3000);
System.out.println("Balance: "+account.getBalance());
System.out.println("Monthly Interest: "+account.getMonthlyInterest());
System.out.println("Date Created : "+account.getDateCreated());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.