Here's the code for that:
public class DTSavingsAccount {
private double balance;
private double interestRate;
private double totalInterest;
private double totalDeposit;
private double totalWithdraw;
//private double startingBalance;
public DTSavingsAccount(double a, double B)/>
{
balance = a;
interestRate = b;
totalDeposit = 0.00;
totalWithdraw = 0.00;
totalInterest = 0.00;
}
public void setInterestRate(double B)/>
{
interestRate = b;
}
public void setBalance(double a)
{
balance = a;
}
public double getInterestRate()
{
return interestRate;
}
public double getBalance()
{
return balance;
}
public void deposit(double amount1)
{
totalDeposit += amount1;
balance += amount1;
}
public void withdraw( double amount2 )
{
totalWithdraw += amount2;
balance -= amount2;
}
public void computeInterest()
{
totalInterest += balance * ((interestRate/100)/12);
balance += balance * ((interestRate/100)/12);
}
public boolean equals(Savings account)
if(interestRate == account.interestRate && balance == account.balance)
{
return true;
}
if else
{
return false;
}
}
the errors for this code are:
F:\Foundations of Java\SavingsAccount.java:59: error: ';' expected
public boolean equals(Savings account)
^
F:\Foundations of Java\SavingsAccount.java:65: error: illegal start of type
if else
^
F:\Foundations of Java\SavingsAccount.java:65: error: ';' expected
if else
^
3 errors
Tool completed with exit code 1
The second part of this problem is
Test the class in a program that calculates the balance of a savings account at the end of a period of time. it should ask the user for the the annual interest rate, the starting balance, and the number of months that have passed since the account was established.A loop should then iterate once for every month, performing the following:
a. ask the user for the amount deposited into the account during the month. use the class method to add this amount to the account balance.
b. ask the user for the amount withdrawn from the account during the month. Use the class method to subtract this amount from the account balance.
c.use the class method to calculate the monthly interest.
After the last iteration, the program should display the ending balance, the total amount of deposit, the total amount of withdrawals, and the total interest earned.
The code is:
import java.util.Scanner;
public class DTSavingsAccountsDemo {
public static void main(String[] args) {
int i;
int option = 0;
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter the month: ");
int month = keyboard.nextInt();
System.out.println("Please enter the balance: ");
double balance = keyboard.nextDouble();
System.out.println("Please enter the annual interest: ");
double interestRate = keyboard.nextDouble();
Savings account = new Savings(balance, interestRate);
for(i = 1; i <= month; i++)
{
System.out.println("*1. Deposit *");
System.out.println("*2. Withdrawal *");
option = keyboard.nextInt();
if(option == 1)
{
System.out.println("Please enter the deposited amount: ");
account.deposit(keyboard.nextDouble());
account.computeInterest();
}
else if(option == 2)
{
System.out.println("Please enter the withdrawal amount: ");
account.withdraw(keyboard.nextDouble());
account.computeInterest();
}
else
{
System.out.println("Wrong Input!");
System.exit(0);
}
}
System.out.println(account);
}
}
The errors are:
F:\Foundations of Java\DTSavingsAccountDemo.java:3: error: class DTSavingsAccountsDemo is public, should be declared in a file named DTSavingsAccountsDemo.java
public class DTSavingsAccountsDemo {
^
F:\Foundations of Java\DTSavingsAccountDemo.java:29: error: cannot find symbol
Savings account = new Savings(balance, interestRate);
^
symbol: class Savings
location: class DTSavingsAccountsDemo
F:\Foundations of Java\DTSavingsAccountDemo.java:29: error: cannot find symbol
Savings account = new Savings(balance, interestRate);
^
symbol: class Savings
location: class DTSavingsAccountsDemo
3 errors
Tool completed with exit code 1
Can you please help me fix the errors in both the codes so they can run perfectly.
Thank you
(also examples of the corrections are better and will be easier for me to understand what your trying to say)

New Topic/Question
Reply



MultiQuote





|