Design a class named Account that contains: -private int data field named id for
ID: 3841038 • Letter: D
Question
Design a class named Account that contains:
-private int data field named id for the account (default 0)
-private double data field named balance for the account (default 0)
-private double field named annualInterest Rate that store the current interest rate(default 0) Assume all accounts have the same interest rate
-private Date field named dateCreated that store the date when the account was created.
-default constructor that creates a default account
-constructor that creates a account with the specified id & initial balance.
-Accessor & mutator methods for id, balance, & annualInterestRate
-Accessor method for dateCreated
-Method named getMonthly InterestRate( that returns the monthly interest rate
-Method names getMonthlyInterest() that returns the monthly interest
-method named withdraw that withdraws a specified amount from the account
-method named deposit that deposits a specific amount to the account
-Write a test demo program that creates an Account object with an ID of 1122, a balance of $20,000.00, & an annual interest rate of 4.5%.
-Use the withdraw method to withdraw $2,500 & use the deposit method to deposit $3,000, $ print the balance, the monthly interest, & the date when this account was created.
Explanation / Answer
class Account
{
private:
int id;
double balance;
double annualInterestRate;
Date dateCreated;
Account()
{
this.id=0;
this.balance=0.0;
this.annualInterestRate=0.0;
}
Account(int id, double balance)
{
this.id = id;
this.balance = balance;
}
void setId(int id)
{
this.id = id;
}
int getId()
{
return this.id;
}
void setBalance(double balance)
{
this.balance = balance;
}
double getBalance()
{
return balance;
}
void setAnnualInterestRate(double annualInterestRate)
{
this.annualInterestRate= annualInterestRate;
}
Date getDatecreated()
{
return this.dateCreated();
}
double getMonthlyInterestRate()
{
double monthly = this.annualInterestRate/12;
return monthly;
}
double getMonthlyInterest()
{
double amount = (this.balance *this.annualInterestRate *100)/12;
return amount;
}
double withDraw(doubel amount)
{
this.balance-= amount;
return this.balance;
}
double deposit(double amount)
{
this.balance+= amount;
return this.balance;
}
public static void main(String args[])
{
Account acc = new Account(1122,20000.00);
acc.setAnnualInterestRate(4.5);
double withDraw = acc.withDraw(2500.00);
double deposit = acc.deposit(3000.00);
System.out.println("Balance after withdrawing amount is " + withDraw);
System.out.println("Balance after depositing amount is " + deposit);
System.out.println("Date accoutn created " + acc.getDateCreated());
System.out.println("Monthly Interest " + acc.getMonthlyInterest());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.