Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Here is the code I was given: /** The BankAccount class simulates a bank account. */ public class BankAccount { private double balance; // Account
Here is the code I was given:
/** The BankAccount class simulates a bank account. */ public class BankAccount { private double balance; // Account balance /** This constructor sets the starting balance at 0.0. */ public BankAccount() { balance = 0.0; } /** This constructor sets the starting balance to the value passed as an argument. @param startBalance The starting balance. */ public BankAccount(double startBalance) { balance = startBalance; } /** This constructor sets the starting balance to the value in the String argument. @param str The starting balance, as a String. */ public BankAccount(String str) { balance = Double.parseDouble(str); } /** The deposit method makes a deposit into the account. @param amount The amount to add to the balance field. */ public void deposit(double amount) { balance += amount; } /** The deposit method makes a deposit into the account. @param str The amount to add to the balance field, as a String. */ public void deposit(String str) { balance += Double.parseDouble(str); } /** The withdraw method withdraws an amount from the account. @param amount The amount to subtract from the balance field. */ public void withdraw(double amount) { balance -= amount; } /** The withdraw method withdraws an amount from the account. @param str The amount to subtract from the balance field, as a String. */ public void withdraw(String str) { balance -= Double.parseDouble(str); } /** The setBalance method sets the account balance. @param b The value to store in the balance field. */ public void setBalance(double b) { balance = b; } /** The setBalance method sets the account balance. @param str The value, as a String, to store in the balance field. */ public void setBalance(String str) { balance = Double.parseDouble(str); } /** The getBalance method returns the account balance. @return The value in the balance field. */ public double getBalance() { return balance; } }
and here is the test program
import javax.swing.JOptionPane; // For the JOptionPane class import java.text.DecimalFormat; // For the DecimalFormat class /** This program demonstrates the BankAccount class. */ public class AccountTest { public static void main(String[] args) { String input; // To hold user input // Create a DecimalFormat object for displaying dollars. DecimalFormat dollar = new DecimalFormat("#,###.00"); // Get the starting balance. input = JOptionPane.showInputDialog("What is your " + "account's starting balance?"); // Create a BankAccount object. BankAccount account = new BankAccount(input); // Get the amount of pay. input = JOptionPane.showInputDialog("How much were " + "you paid this month? "); // Deposit the user's pay into the account. account.deposit(input); // Display the new balance. JOptionPane.showMessageDialog(null, "Your pay has been deposited. " + "Your current balance is $ " + dollar.format(account.getBalance())); // Withdraw some cash from the account. input = JOptionPane.showInputDialog("How much would " + "you like to withdraw? "); account.withdraw(input); // Display the new balance JOptionPane.showMessageDialog(null, "Now your balance is $" + dollar.format(account.getBalance())); System.exit(0); } }
and this is the assignment
add a new method to the BankAccount class: boolean isOverDrawn() This method will return true if the account balance is less than 0.
Then create a UML file for the BankAccount class. Submit the UML file as well as the BankAccount and AccountDemo Java files.
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