Answer to Question #269486 in Java | JSP | JSF for Candy

Question #269486

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 annualInterestRate that stores the current

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.

 A no-arg constructor that creates a default account.

 A constructor that creates an account with the specified id and initial balance.

 The accessor and mutator methods for id, balance, and annualInterestRate.

 The accessor method for dateCreated.

 A method named getMonthlyInterestRate() that returns the monthly interest rate.

 A method named withdraw that withdraws a specified amount from the account.

 A method named deposit that deposits a specified amount to the account.

 Draw the UML diagram for the class.

 Implement the class.


1
Expert's answer
2021-11-21T17:37:28-0500
class Account {
    private int id = 0;
    private double bal = 0.0;
    private static double annualRate = 0.0;
    private java.util.Date dateCreated;


    public Account() {
        dateCreated = new java.util.Date();
    }


    public Account(int id, double balace) {
        this();
        this.id = id;
        this.bal = bal;
    }


    public int getId() {
        return this.id;
    }


    public double getBalance() {
        return this.bal;
    }


    public double getAnnualInterestRate() {
        return annualRate;
    }


    public String getDateCreated() {
        return this.dateCreated.toString();
    }


    public void setId(int id) {
        this.id = id;
    }


    public void setBalance(double bal) {
        this.bal = bal;
    }


    public void setannualRate(double annualRate) {
        this.annualRate = annualRate;
    }


    public double getMonthlyInterestRate() {
        return (annualRate / 100) / 12 ;
    }


    public double getMonthlyInterest() {
        return bal * getMonthlyInterestRate();
    }


    public void withdraw(double amount) {
        this.bal -= amount;
    }


    public void deposit(double amount) {
        this.bal += amount;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS