I need this in java Part 1 Design a class named Account that contains: . A priva
ID: 3712124 • Letter: I
Question
I need this in java
Part 1 Design a class named Account that contains: . A private String data field named FirstName for the account. .A private String data field named LastName for the account. .A private int data field named id for the account A private double data field named balance for the account. .A private double data field named monthlyInterestRate that stores the current interest rate (default 4.5). 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 method named get MonthlylnterestO that returns the monthly interest. A method named withdraw that withdraws a specified amount from the account. Note: You need to check if the specified amount is less than or equal to the balance. You cannot withdraw more than what you have in your account . CREENS 1-3 OF 5Explanation / Answer
SourceCode:
Account.java:
package Demo;
import java.util.ArrayList;
import java.util.Date;
public class Account {
private int id;
private double balance;
private double annualInterestRate = 0.0;
private Date dateCreated ;
private String name;
private ArrayList<Transaction> transaction;
public Account()
{
transaction = new ArrayList<Transaction>();
}
public Account(int id,double bal){
this();
this.id = id;
this.balance = bal;
}
public Account(int id,String name,double bal){
this();
this.id = id;
this.balance = bal;
this.name = name;
}
public int getId()
{
return id;
}
public double getBalance(){
return balance;
}
public double getAnnualInterestRate()
{
return annualInterestRate;
}
public void setId(int id){
this.id = id;
}
public void setBalance(double bal){
this.balance = bal;
}
public void setannualInterestRate(double rate)
{
this.annualInterestRate = rate;
}
public Date getDateCreated(){
return dateCreated;
}
public double getMonthlyInterestRate(){
return annualInterestRate / 12;
}
public double getMonthlyInterest(){
return (balance * annualInterestRate) / (100 * 12);
}
public void withdraw(double amt)
{
if(balance > amt){
balance -= amt;
Transaction t = new Transaction('w', amt, this.balance, "Amount withdraw");
transaction.add(t);
}
else{
System.out.println("In sufficient balance");
}
}
public void deposit(double amt){
balance = balance + amt;
Transaction t = new Transaction('d', amt, this.balance, "Amount deposit");
transaction.add(t);
}
public void print()
{
System.out.println("Name:"+name+" Interest Rate:"+annualInterestRate+" Balance:"+balance);
for(Transaction t : transaction ){
System.out.println(t.print());
}
}
}
class Transaction{
private Date date;
private double balance;
private double amount;
private char type;
private String description;
public Transaction(char type,double amt,double bal,String desc){
balance = bal;
this.type = type;
this.amount = amt;
description = desc;
}
public String print()
{
return "Balance:"+balance+" Amount:"+amount+" Type:"+type+" Description:"+description;
}
}
Test.java:
package Demo;
public class Test {
public static void main(String[] args) {
Account act = new Account(1122,"George",1000);
act.setannualInterestRate(1.5);
act.deposit(30);
act.deposit(40);
act.deposit(50);
act.withdraw(5);
act.withdraw(4);
act.withdraw(2);
act.print();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.