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

There is a problem in BankAccount class. There is a problem with Deposits and Wi

ID: 3829571 • Letter: T

Question

There is a problem in BankAccount class. There is a problem with Deposits and Withdrawals. Step through the program via the Debugger and determine what and where the problem is. Then comment out the bad code and put in new code to fix the problem, and add a comment above your change.

The ending Balance should be: $5.51

Starting balance = $100
Total of Deposits = $70 (added to balance)
Total of Withdraws = $162 (subtracted from balance)
Interest made = .01 (rounded from 0.01375) (added to balance)
Service Charge = $2.50 (subtracted from balance)

/**
The BankAccount class stores data about a bank account
for the BankAccount and SavingsAccount Classes
programming challenge.

There is a problem with Deposits and Withdrawals.
Step through the program via the Debugger and determine
what and where the problem is. Then comment out the bad
code and put in new code to fix the problem, and add
a comment above your change.
*/

public class BankAccount1
{
private double balance; // Account balance
private int numDeposits; // Number of deposits
private int numWithdrawals; // Number of withdrawals
private double interestRate; // Interest rate
private double monthlyServiceCharges; // Service charges

/**
The constructor initializes the account with
a balance, an interest rate, and monthly
service charges.
@param bal The balance.
@param intRate The interest rate.
@param mon The monthly service charges.
*/

public BankAccount1(){}

public BankAccount1(double bal, double intRate,double monthly)
{
balance = bal;
interestRate = intRate;
monthlyServiceCharges = monthly;
numDeposits = 0;
numWithdrawals = 0;
}

/**
The deposit method makes a deposit
into the account.
@param amount The amount to deposit.
*/

public void deposit(double amount)
{
balance += numDeposits;
numDeposits++;
}

/**
The withdraw method withdraws an amount
from the account.
@param amount The amount to withdraw.
*/

public void withdraw(double amount)
{
balance -= numWithdrawals;
numWithdrawals++;
}

/**
The calcInterest method calculates the monthly
interest and adds it to the account balance.
*/

private void calcInterest()
{
// Get the monthly interest rate.
double monIntRate = interestRate / 12;
  
// Get the amount of interest for the month.
double monInterest = balance * monIntRate;
  
// Add the interest to the balance.
balance += monInterest;
}

/**
The monthlyProcess method subtracts the
monthly service charge from the account
balance and adds the monthly interest.
The number of deposits and number of
withdrawals are set to 0.
*/

public void monthlyProcess()
{
// Subtract the monthly service charges
// from the balance.
balance -= monthlyServiceCharges;
  
// Calculate and add the interest for
// the month.
calcInterest();
  
// Reset the number of deposits and
// withdrawals to zero.
numDeposits = 0;
numWithdrawals = 0;
}

/**
The setMonthlyServiceCharges method sets
the monthly service charge to a specified
amount.
@param m The amount of monthly service charge.
*/

public void setMonthlyServiceCharges(double m)
{
monthlyServiceCharges = m;
}

/**
The getBalance method returns the account balance.
@return The account balance.
*/

public double getBalance()
{
return balance;
}

/**
The getNumDeposits method returns the
number of deposits.
@return The number of deposits.
*/

public int getNumDeposits()
{
return numDeposits;
}

/**
The getNumWithdrawals method returns the
number of withdrawals.
@return The number of withdrawals.
*/

public int getNumWithdrawals()
{
return numWithdrawals;
}

/**
The getInterestRate method returns the
interest rate.
@return The interest rate.
*/

public double getInterestRate()
{
return interestRate;
}

/**
The getMonthlyServiceCharges method returns
the monthly service charges
@return The motnhly service charges.
*/

public double getMonthlyServiceCharges()
{
return monthlyServiceCharges;
}
}

import java.text.DecimalFormat;

/**
This program demonstrates a solution to the
BankAccount and BankAccount Classes
programming challenge.
*/

public class BankingDemo1
{
public static void main(String[] args)
{
// Create a Decimalformat object for formatting output.
DecimalFormat dollar = new DecimalFormat("#,##0.00");
  
// Create a BankAccount object with a $100 balance,
// 3% interest rate, and a monthly service charge
// of $2.50.
BankAccount1 banking = new BankAccount1(100.0,.03,2.5);
  
// Display what we've got.
System.out.println("Balance: $" +
dollar.format(banking.getBalance()));
System.out.println("Number of deposits: " +
banking.getNumDeposits());
System.out.println("Number of withdrawals: " +
banking.getNumWithdrawals());
System.out.println();
  
// Make some deposits.
banking.deposit(25.00);
banking.deposit(10.00);
banking.deposit(35.00);
  
// Display what we've done so far.
System.out.println("Balance: $" +
dollar.format(banking.getBalance()));
System.out.println("Number of deposits: " +
banking.getNumDeposits());
System.out.println("Number of withdrawals: " +
banking.getNumWithdrawals());
System.out.println();
  
// Make some withdrawals.
banking.withdraw(100.00);
banking.withdraw(50.00);
banking.withdraw(10.00);
banking.withdraw(1.00);
banking.withdraw(1.00);
  
// Display what we've done so far.
System.out.println("Balance: $" +
dollar.format(banking.getBalance()));
System.out.println("Number of deposits: " +
banking.getNumDeposits());
System.out.println("Number of withdrawals: " +
banking.getNumWithdrawals());
System.out.println();

// Do the monthly processing.
banking.monthlyProcess();

// Display what we've done so far.
System.out.println("Balance: $" +
dollar.format(banking.getBalance()));
System.out.println("Number of deposits: " +
banking.getNumDeposits());
System.out.println("Number of withdrawals: " +
banking.getNumWithdrawals());
}
}

Explanation / Answer

import java.text.DecimalFormat; //use import statement at first

public class BankAccount1
{
private double balance; // Account balance
private int numDeposits; // Number of deposits
private int numWithdrawals; // Number of withdrawals
private double interestRate; // Interest rate
private double monthlyServiceCharges; // Service charges

/**
The constructor initializes the account with
a balance, an interest rate, and monthly
service charges.
@param bal The balance.
@param intRate The interest rate.
@param mon The monthly service charges.
*/

public BankAccount1(){}

public BankAccount1(double bal, double intRate,double monthly)
{
balance = bal;
interestRate = intRate;
monthlyServiceCharges = monthly;
numDeposits = 0;
numWithdrawals = 0;
}

/**
The deposit method makes a deposit
into the account.
@param amount The amount to deposit.
*/

public void deposit(double amount)
{
balance += amount; //balance should be added with amount
numDeposits++;
}

/**
The withdraw method withdraws an amount
from the account.
@param amount The amount to withdraw.
*/

public void withdraw(double amount)
{
balance -= amount; //amount should be deducted from balance
numWithdrawals++;
}

/**
The calcInterest method calculates the monthly
interest and adds it to the account balance.
*/

private void calcInterest()
{
// Get the monthly interest rate.
double monIntRate = interestRate / 12;
  
// Get the amount of interest for the month.
double monInterest = balance * monIntRate;
  
// Add the interest to the balance.
balance += monInterest;
}

/**
The monthlyProcess method subtracts the
monthly service charge from the account
balance and adds the monthly interest.
The number of deposits and number of
withdrawals are set to 0.
*/

public void monthlyProcess()
{
// Subtract the monthly service charges
// from the balance.
balance -= monthlyServiceCharges;
  
// Calculate and add the interest for
// the month.
calcInterest();
  
// Reset the number of deposits and
// withdrawals to zero.
numDeposits = 0;
numWithdrawals = 0;
}

/**
The setMonthlyServiceCharges method sets
the monthly service charge to a specified
amount.
@param m The amount of monthly service charge.
*/

public void setMonthlyServiceCharges(double m)
{
monthlyServiceCharges = m;
}

/**
The getBalance method returns the account balance.
@return The account balance.
*/

public double getBalance()
{
return balance;
}

/**
The getNumDeposits method returns the
number of deposits.
@return The number of deposits.
*/

public int getNumDeposits()
{
return numDeposits;
}

/**
The getNumWithdrawals method returns the
number of withdrawals.
@return The number of withdrawals.
*/

public int getNumWithdrawals()
{
return numWithdrawals;
}

/**
The getInterestRate method returns the
interest rate.
@return The interest rate.
*/

public double getInterestRate()
{
return interestRate;
}

/**
The getMonthlyServiceCharges method returns
the monthly service charges
@return The motnhly service charges.
*/

public double getMonthlyServiceCharges()
{
return monthlyServiceCharges;
}
}

/**
This program demonstrates a solution to the
BankAccount and BankAccount Classes
programming challenge.
*/

public class BankingDemo1
{
public static void main(String[] args)
{
// Create a Decimalformat object for formatting output.
DecimalFormat dollar = new DecimalFormat("#,##0.00");
  
// Create a BankAccount object with a $100 balance,
// 3% interest rate, and a monthly service charge
// of $2.50.
BankAccount1 banking = new BankAccount1(100.0,.03,2.5);
  
// Display what we've got.
System.out.println("Balance: $" +
dollar.format(banking.getBalance()));
System.out.println("Number of deposits: " +
banking.getNumDeposits());
System.out.println("Number of withdrawals: " +
banking.getNumWithdrawals());
System.out.println();
  
// Make some deposits.
banking.deposit(25.00);
banking.deposit(10.00);
banking.deposit(35.00);
  
// Display what we've done so far.
System.out.println("Balance: $" +
dollar.format(banking.getBalance()));
System.out.println("Number of deposits: " +
banking.getNumDeposits());
System.out.println("Number of withdrawals: " +
banking.getNumWithdrawals());
System.out.println();
  
// Make some withdrawals.
banking.withdraw(100.00);
banking.withdraw(50.00);
banking.withdraw(10.00);
banking.withdraw(1.00);
banking.withdraw(1.00);
  
// Display what we've done so far.
System.out.println("Balance: $" +
dollar.format(banking.getBalance()));
System.out.println("Number of deposits: " +
banking.getNumDeposits());
System.out.println("Number of withdrawals: " +
banking.getNumWithdrawals());
System.out.println();

// Do the monthly processing.
banking.monthlyProcess();

// Display what we've done so far.
System.out.println("Balance: $" +
dollar.format(banking.getBalance()));
System.out.println("Number of deposits: " +
banking.getNumDeposits());
System.out.println("Number of withdrawals: " +
banking.getNumWithdrawals());
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote