The Account class ) Design a class named Account that contains: A private intdat
ID: 3854947 • Letter: T
Question
The Account class) Design a class named Account that contains:
A private intdata field named id for the account (default 0).
A private String data field namefor the account (default “No Name yet”)
A private doubledata field named balance for the account (default 0).
A private doubledata field named annualInterestRate that stores the current interest rate (default 0).
A private Datedata field named dateCreated that stores the date when the account was created. (You may make this a String field and access the date with the .toString()method in String.
A private int data field named transactionsfor the account (default is 0).
A private intstatic data field named numberOfAccounts that stores the current number of accounts created.
A no-arg constructor that creates a default account.
A constructor that creates an account with the specified id, name, initial balance,and annualInterestRate.
The accessor and mutator methods for id, name, balance, and annualInterestRate.
The accessor method for dateCreated.
A method named withdrawthat withdraws a specified amount from the account.
A method named depositthat deposits a specified amount to the account.
A method named displayAccountwhich will show all the information in the account.
A method name transferFunds which will transfer money from one account to another.
Explanation / Answer
The desired Account Class with proper comments is given below:
public class Account
{
//private member variable
private int id;
private String name;
private double balance;
private double annualInterestRate;
private String dataCreated;
private int transactionsfor;
private static int numberOfAccounts;
//Accessor Methods and Mutator Methods
public String getAccountCreatedDate()
{
return dataCreated;
}
public int getAccountId()
{
return id;
}
public void setAccountId(int temp_Id)
{
id = temp_Id;
}
public String getAccountName()
{
return name;
}
public void setAccountName(String temp_Name)
{
name = temp_Name;
}
public double getAccountBalance()
{
return balance;
}
public void setAccountBalance(double temp_Bal)
{
balance = temp_Bal;
}
public double getAccountInterestRate()
{
return annualInterestRate;
}
public void setAccountInterestRate(double temp_Rate)
{
annualInterestRate = temp_Rate;
}
//Default Constructor of Account class (no-arg constructor)
public Account()
{
id = 0;
name = "No Name yet";
balance = 0;
annualInterestRate = 0;
transactionsfor = 0;
}
//Constructor with parameters
public Account(int temp_Id, String temp_Name, double temp_Bal, double interestRate)
{
id = temp_Id;
name = temp_Name;
balance = temp_Bal;
annualInterestRate = interestRate;
}
//Method for depositing money
public void depositthat(double amt)
{
balance = balance + amt;
}
//Method for money withdraw
public void withdrawthat(double amt)
{
balance = balance - amt;
}
//Method for display account details
public void displayAccountwhich()
{
System.out.println("The account id is: " + id);
System.out.println("The account name is: " + name);
System.out.println("The account balance is: " + balance);
System.out.println("The account is created on date: " + dataCreated);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.