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

D *SavingsAccount.java × 1 package code; 3 public class SavingsAccount /* Task *

ID: 3603496 • Letter: D

Question

D *SavingsAccount.java × 1 package code; 3 public class SavingsAccount /* Task *Define this class to that represents a simple Savings Account Pay attention to the names, parameters and return types of the methods described. They must be exactly as given, else the code won't compile * on AutoLab 10 *The account object must have two private instance variables, one of type * double representing the current balance, and the other of type boolean *indicating whether the account has authorization to perform a withdrawal L2 13 14 15 16 17 18 *The balance of the account must never go below zero. A withdrawal must * not be done unless there is prior authorization. If authorization has *been obtained a single withdrawal can be performed. Performing an *authorized withdrawal rescinds the withdrawal, preventing any additional *withdrawals from taking place until authorization for another withdrawal * is obtained The constructor of the class must initialize the balance to zero, and the * withdrawal authorization to false 24 *The "deposit' method must verify that the amount to be deposited is * non-negative before proceeding with the deposit. The 'deposit' method *must have a void return type * The "withdraw. method must verify that the amount to be withdrawn is 30 31 32 non-negative, that the amount is no greater than the current balance, and that the withdrawal is authorized before proceeding with the withdrawal *The 'withdraw' method must have a void return type 34 * The 'balance' method must return the current balance. It must have a *double return type 36 37 38 39 40 41 The "authorize' method must set the authorization to true. It must have a * void return type The "authorized' method must return the authorization It must have a * boolean return type 43 46

Explanation / Answer

import java.util.Scanner; import java.io.*; public class SavingsAccountClass { class SavingsAccount { private double accountBalance; private double annualInterestRate; private double lastAmountOfInterestEarned; public SavingsAccount(double balance, double interestRate) { accountBalance = balance; annualInterestRate = interestRate; lastAmountOfInterestEarned = 0.0; } public void withdraw(double withdrawAmount) { accountBalance -= withdrawAmount; } public void deposit(double depositAmount) { accountBalance += depositAmount; } public void addInterest() { // Get the monthly interest rate. double monthlyInterestRate = annualInterestRate / 12; // Calculate the last amount of interest earned. lastAmountOfInterestEarned = monthlyInterestRate * accountBalance; // Add the interest to the balance. accountBalance += lastAmountOfInterestEarned; } public double getAccountBalance() { return accountBalance; } public double getAnnualInterestRate() { return annualInterestRate; } public double getLastAmountOfInterestEarned() { return lastAmountOfInterestEarned; } } }