Question
/** P3.2. Adding a method public void addInterest(double rate) to the BankAccount32 class which adds interest at the given rate. */ public class BankAccount32 {
/** P3.2. Adding a method
public void addInterest(double rate)
to the BankAccount32 class which adds interest at the given rate. */ public class BankAccount32 { //instance variable private double balance ;
/** Constructor: initializes balance to zero */ public BankAccount32() { balance = 0 ; } /** Constructor: initializes balance to given initialBalance paramter @param initialBalance */ public BankAccount32(double initialBalance) { balance = initialBalance ; } /** Adds interest to the BankAccount balance at the given rate @param rate the percent of interest to add HINT: don't forget to convert percent to fraction first! */ //-----------Start below here. To do: approximate lines of code = 2 // Write the addInterest method //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. /** Returns the balance @return the balance */ public double getBalance() { return balance ; } /** Deposits amount of money to the account @param amount the amount of money to put in */ public void deposit(double amount) { balance = balance + amount ; } /** Withdraws amount of money to the account @param amount the amount of money to take out */ public void withdraw(double amount) { double newBalance = balance - amount ; balance = newBalance ; } /** Returns a string representation of the account @return the string representation */ public String toString() { return "BankAccount[balance = " + balance + "]" ; } }
//Tester class no need to change
public class BankAccount32Tester { public static void main(String[] args) { BankAccount32 momsSavings = new BankAccount32(1000) ; momsSavings.addInterest(10) ; System.out.printf("%.2f ", momsSavings.getBalance()) ; System.out.println("Expected:") ; System.out.println("1100.00") ; System.out.println("Here is what it is after more interest additions:") ; momsSavings.addInterest(10) ; momsSavings.addInterest(5) ; momsSavings.addInterest(20) ; momsSavings.addInterest(30) ; momsSavings.addInterest(15) ; momsSavings.addInterest(2) ; System.out.printf("%.2f ", momsSavings.getBalance()) ; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started