I need help designing a class named Account that contains. A data field named id for the account (default 0 ). A data field named balance for the account (default 0.0 ). A data field named annualInterestRate that stores the current interest rate (default 0.0 ). Assume all accounts have the same interest rate. Program can create a default account. Program can create an account with a specified id and initial balance. A method named getMonthlyInterest() returns the amount of interest an account earned that month. A method named setInterestRate() that receives and sets the interest rate for all accounts. A method named getInterestRate() that returns the interest rate for all accounts. A method named withdraw() that withdraws a specified amount from the account returns T or F. A method named deposit() that deposits a specified amount to the account returns T or F. A method named getBalance() that returns the balance amount to the account. (Hint: The method getMonthlyInterest() is to return monthly interest earned, not the interest rate. As well as a test driver that creates an Account object and test all aspects of the designed Accounts class. This Java program will create a default account and create an account with the specified id and initial balance.
I need help designing a class named Account that contains.
- A data field named id for the account (default 0 ).
- A data field named balance for the account (default 0.0 ).
- A data field named annualInterestRate that stores the current interest rate (default 0.0 ). Assume all accounts have the same interest rate.
- Program can create a default account.
- Program can create an account with a specified id and initial balance.
- A method named getMonthlyInterest() returns the amount of interest an account earned that month.
- A method named setInterestRate() that receives and sets the interest rate for all accounts.
- A method named getInterestRate() that returns the interest rate for all accounts.
- A method named withdraw() that withdraws a specified amount from the account returns T or F.
- A method named deposit() that deposits a specified amount to the account returns T or F.
- A method named getBalance() that returns the balance amount to the account.
(Hint: The method getMonthlyInterest() is to return monthly interest earned, not the interest rate.
As well as a test driver that creates an Account object and test all aspects of the designed Accounts class.
This Java program will create a default account and create an account with the specified id and initial balance.
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Account acc = new Account();
acc.SetID(1122);
acc.SetBalance(20000);
acc.SetIntrestRate(4.5);
System.out.println("After withdraw balance : "+acc.withdraw(2500));
System.out.println("After deposit balance : "+acc.deposit(3000));
System.out.println("Monthly intrest is : "+acc.getMonthlyIntrest());
System.out.println("Date when account is created : "+acc.GetDateCreated().toString());
System.out.println("Checking for insufficiant funds -> "+acc.withdraw(50000));
}
}
class Account
{
private int id;
private double balance;
private double annualIntrestRate;
private Date dateCreated;
Account()
{
id = 0;
balance = 0.0;
annualIntrestRate = 0.0;
dateCreated = new Date();
}
Account(int id,double balance)
{
this.id = id;
this.balance = balance;
annualIntrestRate = 0.0;
dateCreated = new Date();
}
public int GetID()
{
return id;
}
public double GetBalance()
{
return balance;
}
public double GetIntrestRate()
{
return annualIntrestRate;
}
public void SetID(int id)
{
this.id = id;
}
public void SetBalance(double balance)
{
this.balance = balance;
}
public void SetIntrestRate(double intrestRate)
{
this.annualIntrestRate = intrestRate;
}
public Date GetDateCreated()
{
return dateCreated;
}
public double getMonthlyIntrest()
{
double monthIntrestRate = annualIntrestRate/12;
return (balance * monthIntrestRate)/100;
}
public double withdraw(double amount)
{
if(!(balance-amount < 0))
{
balance -= amount;
}
else
{
System.out.println("Can't withdraw more than balance");
}
return balance;
}
public double deposit(double amount)
{
balance += amount;
return balance;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images