Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab Activities: Account Class Ia this lab, you will (a)wite a class that represe

ID: 3594331 • Letter: L

Question

Lab Activities: Account Class Ia this lab, you will (a)wite a class that represents a model of a topical bank Account and Q) a test class to test it t. Draw the L class diagram for your design (relating the 2 classes below) a class named Account. Use the Java keyword this in its TWO forms of usage named Aecount. H. Write a Java source code for ta.) to call a constractor from another constructor;, and (2.) to refer to the referenced objeet] everywhere you need. Make sure all the data field members (data fields) are private e represents a tspical Accoust Gin the form of an Account Java object). Write the Account class that is briefly described beow An Account object, an instance of Account class, has the following properties and methods: -state (expressed via its private data fBelds) can be defined as the following Account's properties: id, name, (of the account holder) balance, annwallnterestRate, and dateCreated, and behavior (expressed via its methods) is to withdraw, depasit and to get the monthly interest rate. (I) The Account data field id is int, name is String, balance is double, annualInterestRate is double and atatic, dateCreated is java.util.Date. (You may import the java.util library in the beginning of this Java file; then to declare this data field you will use only the data type Date (2) Write two constructors. Use the Java this keyword to call one of the constructors from the other. The first constructor takes id and name as formal parameters. Then, it calls the second constructor (using the Java this keyword) with the id, name, default balance of 0 and a default interest rate (annualhe restate) of 0.75 (3) The second constructor takes id, mame, balance, annualinterestRate as formal parameters and initializes the resp ective Account data fields (use this Java keyword to do this). It also should create a date of the opening of the accouat by initializing the dateCreated data field with the current date (4) Implement set methods (also called mutators, setters) for the data ficlds' instance variables: id, balance, and annuallnterestRate; i.e., do not implement a set method for the dateCreated and name data field (5) Implement get methods (also called accessors, getters) for id, name, balance, annuallnterestRate, and (6) Write the withdraw) method: It takes as a parameter an amount withdrawn and rcturns nothing (ie., dateCreated void); it reduces the balance with the amount withdrawn. However, before you do this change, check if the balance is more than the amount to be withdrawn (with if statement) so that you do not end up with negative balance (7) Write the deposit () method: It takes as a parameter an amount to be deposited and returns nothing; it increases the balance with the amount deposited (8) Write the getMonthlyInterest () method: It takes no parameter and returns double; it calculates the monthly interest dollar amount gained from the interest for one month (as a real number-double). Note you must use the monthly interest rate her multiplied by the balance. 9) Include a tostring () method to return the output for each Account in the following format (notice, this is just an example): 123456 e: John Smith ance: $1,598.00 al Interest Rate: 2.0 Created: Sun Mar 25 14 (10)If you use only the data field balance (in the example above for the 1598 amount) in the tostring () method it will not look like a currency (money), i.e.-like above. THEREFORE, when you prepatre the format of the balance, make sure that you use the NumberFormat object to p t in the format of a currency (money) value. Use this object in the following way o Firstly, declare and create the object currencyFormyalue Page 2 of 5 .

Explanation / Answer

import java.util.Date;

public class Account {

private int id;

private String name;

private double balance;

private double annualIntrestRate;

private Date dateCreated;

public Account(int id, String name) {

this.id = id;

this.name = name;

}

public Account(int id, String name,double balance,double annualIntrestRate) {

this(id,name);

this.balance = 0;

this.annualIntrestRate =0.75;

}

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public double getBalance() {

return balance;

}

public void setBalance(double balance) {

this.balance = balance;

}

public double getAnnualIntrestRate() {

return annualIntrestRate;

}

public void setAnnualIntrestRate(double annualIntrestRate) {

this.annualIntrestRate = annualIntrestRate;

}

public void withdraw(double amount)

{

if(balance>amount)

{

balance=balance-amount;

}

}

public void deposit(double amount)

{

balance=balance+amount;

}

public double getMonthlyIntrest()

{

return annualIntrestRate*balance*(1/24);

}

public String toString() {

return "Account [id=" + id + ", name=" + name + ", balance=" + balance + ", annualIntrestRate="

+ annualIntrestRate + ", dateCreated=" + dateCreated + "]";

}

}

public class Test {

public static void main(String[] args) {

// TODO Auto-generated method stub

Account account1=new Account(1,"account1");

Account account2=new Account(1,"account2");

Account account3=new Account(1,"account3");

System.out.println(account1);

System.out.println(account2);

System.out.println(account3);

account1.setBalance(1000.0);

account1.setId(11);

account2.setId(22);

account3.setId(33);

account2.setBalance(2000.0);

account3.setBalance(3000.0);

System.out.println(account1);

System.out.println(account2);

System.out.println(account3);

}

}