Close Lab 2: Create and ase a class Problem Description: The Account clasa) Desi
ID: 3742603 • Letter: C
Question
Close Lab 2: Create and ase a class Problem Description: The Account clasa) Design a class mamed Accoune that contains: A private int data tield named d tox the accoust (detault 0 ) .A private double data field aaned balasce for the account (detault ) stores the current interest rate (defauE O).Assune al1 . A private double data field haned annualinterestRate that accounts have the same Interest zate .A private Date data field naned dateCrested that stores the date when the account was created. .A no-arg constructor that ereates a defauit account . A constructor that creates an account with the specified id and initial balance The accessor and mutator methods for id balarce and annual InterestRate The accessor method for dateCrested . A method named getMonthlyIaterestRaten that seturna the monthly interest zate A method named withdraw that withdzaws a specified anount feom the account A method named deposit that deposits specified anount to the account Draw the UNL diagran for the class. Implenent the class Write a test program that creates an Account object with an account ID of 1122, a balance oE 320.0dd, and an anual interest rate of 4.58. Use the withdrav nethod to vithdras 2,500 use the deposit method to deposit $3,co0, and print the balance, the monthly interest, and the date when this account was creatod. Analysis Describe the problem including input and output in your own words Design: Draw an UML class diagram for the Account class Coding: (main testing part provided publie elass Test publie statie void sain Szzing1 82) Account account-new Account 71 122 2000 t.setAnnusiInter ecoune.withdraW (2300 aceount-deposit (300) Systes.our.princn Honthly snterest ystem our.prinein hisecoun as ereated a account ge bateCreated0 Class Acoount // Inp eneat the elass hezeExplanation / Answer
//Account.java class
import java.util.Date;
class Account
{
private int id;
private double balance;
private Date dateCreated;
private double anualInterestRate;
public Account()
{
Date dateCreated = new Date();
//System.out.println("toString(): " + now);
//System.out.println(dateFormat.format(dateCreated));
id=0;
balance=0;
anualInterestRate=0;
}
public Account(int id1,double bal)
{
dateCreated=new Date();
//System.out.println(dateFormat.format(dateCreated));
id=id1;
balance=bal;
}
public void set_id(int id1)
{
id=id1;
}
public void set_balance(double bal)
{
balance =bal;
}
public String getDateCreated()
{
return dateCreated.toString();
}
public void setAnnualInterestRate(double rate)
{
anualInterestRate=rate/100;
}
int get_id()
{
return id;
}
public double getBalance()
{
return balance;
}
public double getMonthlyInterestRate()
{
return anualInterestRate/12;
}
void withdraw(double amt)
{
balance-=amt;
}
void deposit(double amt)
{
balance+=amt;
}
}
----------------------------------------------------------
//Main.java
public class Main
{
public static void main(String[] args) {
//System.out.println("Hello World");
Account account = new Account(1122,20000);
account.setAnnualInterestRate(4.5);
account.withdraw(2500);
account.deposit(3000);
System.out.println("Balance is "+account.getBalance());
System.out.println("Monthly interest is "+ account.getMonthlyInterestRate());
System.out.println("This account was created at "+account.getDateCreated());
}
}
---------------------------------------------
//output
Balance is 20500.0
Monthly interest is 0.00375
This account was created at Tue Sep 04 11:01:46 UTC 2018
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.