Question: /** This program demonstrates the BankAccount and derived classes. */ public class AccountDriver { public static void main(String[] args) { double put_in = 500; double

![class AccountDriver { public static void main(String[] args) { double put_in =](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f04d8bb7a2e_52366f04d8b3dc84.jpg)

/** This program demonstrates the BankAccount and derived classes. */
public class AccountDriver { public static void main(String[] args) { double put_in = 500; double take_out = 1000;
String money; String money_in; String money_out; boolean completed;
// Test the CheckingAccount class. CheckingAccount myCheckingAccount = new CheckingAccount("Benjamin Franklin", 1000);
System.out.println("Account Number " + myCheckingAccount. getAccountNumber() + " belonging to " + myCheckingAccount.getOwner());
money = String.format("%.2f", myCheckingAccount. getBalance());
System.out.println("Initial balance = $" + money);
myCheckingAccount.deposit(put_in);
money_in = String.format("%.2f", put_in);
money = String.format("%.2f", myCheckingAccount. getBalance());
System.out.println("After deposit of $" + money_in + ", balance = $" + money);
completed = myCheckingAccount.withdraw(take_out);
money_out = String.format("%.2f", take_out);
money = String.format("%.2f", myCheckingAccount. getBalance());
if (completed) { System.out.println("After withdrawal of $" + money_out + ", balance = $" + money); } else { System.out.println("Insuffient funds to " + "withdraw $" + money_out + ", balance = $" + money); }
System.out.println();
// Test the SavingsAccount class. SavingsAccount yourAccount = new SavingsAccount("William Shakespeare", 400);
System.out.println("Account Number " + yourAccount.getAccountNumber() + " belonging to " + yourAccount.getOwner());
money = String.format("%.2f", yourAccount.getBalance());
System.out.println("Initial balance = $" + money);
yourAccount.deposit(put_in);
money_in = String.format("%.2f", put_in);
money = String.format("%.2f", yourAccount.getBalance());
System.out.println("After deposit of $" + money_in + ", balance = $" + money);
completed = yourAccount.withdraw(take_out);
money_out = String.format("%.2f", take_out);
money = String.format("%.2f", yourAccount.getBalance());
if (completed) { System.out.println("After withdrawal of $" + money_out + ", balance = $" + money); } else { System.out.println("Insuffient funds " + "to withdraw $" + money_out + ", balance = $" + money); }
yourAccount.postInterest();
money = String.format("%.2f", yourAccount.getBalance());
System.out.println("After monthly interest " + "has been posted," + "balance = $" + money);
System.out.println();
// Test the copy constructor of the // SavingsAccount class. SavingsAccount secondAccount = new SavingsAccount(yourAccount, 5);
System.out.println("Account Number " + secondAccount. getAccountNumber() + " belonging to " + secondAccount.getOwner());
money = String.format("%.2f", secondAccount.getBalance());
System.out.println("Initial balance = $" + money);
secondAccount.deposit(put_in);
money_in = String.format("%.2f", put_in);
money = String.format("%.2f", secondAccount.getBalance());
System.out.println("After deposit of $" + money_in + ", balance = $" + money);
secondAccount.withdraw(take_out);
money_out = String.format("%.2f", take_out);
money = String.format("%.2f", secondAccount.getBalance());
if (completed) { System.out.println("After withdrawal of $" + money_out + ", balance = $" + money); } else { System.out.println("Insuffient funds " + "to withdraw $" + money_out + ", balance = $" + money); }
System.out.println();
// Test to make sure new accounts are // numbered correctly. CheckingAccount yourCheckingAccount = new CheckingAccount("Issac Newton", 5000);
System.out.println("Account Number " + yourCheckingAccount. getAccountNumber() + " belonging to " + yourCheckingAccount.getOwner()); } }
/** */
In this lab, you will be creating new classes that are derived from a class called BankAccount. A checking account is a bank account and a savings account is a bank account as well. This sets up a relationship called inheritance, where BankAccount is the superclass and CheckingAccount and SavingsAccount are subclasses. This relationship allows CheckingAccount to inherit attributes from BankAccount (like owner, balance, and accountNumber, but it can have new attributes that are specific to a checking account, like a fee for clearing a check. It also allows CheckingAccount to inherit methods from BankAccount, like deposit, that are universal for all bank accounts. You will write a withdraw method in CheckingAccount that overrides the withdraw method in BankAccount, in order to do something slightly different than the original withdraw method. You will use an instance variable called accountNumber in SavingsAccount to hide the accountNumber variable inherited from BankAccount. The UML diagram for the inheritance relationship is as follows: \begin{tabular}{|l|} \hline \multicolumn{1}{|c|}{ BankAccount } \\ \hline \end{tabular} 4. Write a constructor that takes a name and an initial amount as parameters. It should call the constructor for the superclass. It should initialize accountNumber to be the current value in accountNumber concatenated with 10 (All checking accounts at this bank are identified by the extension 10 ). There can be only one checking account for each account number. Remember since accountNumber is a private member in BankAccount, it must be changed through a mutator method. 5. Write a new instance method, withdraw, that overrides the withdraw method in the superclass. This method should take the amount to withdraw, add to it the fee for check clearing, and call the withdraw method from the superclass. Remember that to override the method, it must have the same method heading. Notice that the withdraw method from the superclass returns true or false depending if it was able to complete the withdrawal or not. The method that overrides it must also return the same true or false that was returned from the call to the withdraw method from the superclass. 6. Compile and debug this class. Use the AccountDriver class to test out your classes. If you named and created your classes and methods correctly, it should not have any difficulties. If you have errors, do not edit the AccountDriver class. You must make your classes work with this program. In this lab, you will be creating new classes that are derived from a class called BankAccount. A checking account is a bank account and a savings account is a bank account as well. This sets up a relationship called inheritance, where BankAccount is the superclass and CheckingAccount and SavingsAccount are subclasses. This relationship allows CheckingAccount to inherit attributes from BankAccount (like owner, balance, and accountNumber, but it can have new attributes that are specific to a checking account, like a fee for clearing a check. It also allows CheckingAccount to inherit methods from BankAccount, like deposit, that are universal for all bank accounts. You will write a withdraw method in CheckingAccount that overrides the withdraw method in BankAccount, in order to do something slightly different than the original withdraw method. You will use an instance variable called accountNumber in SavingsAccount to hide the accountNumber variable inherited from BankAccount. The UML diagram for the inheritance relationship is as follows: \begin{tabular}{|l|} \hline \multicolumn{1}{|c|}{ BankAccount } \\ \hline \end{tabular} 4. Write a constructor that takes a name and an initial amount as parameters. It should call the constructor for the superclass. It should initialize accountNumber to be the current value in accountNumber concatenated with 10 (All checking accounts at this bank are identified by the extension 10 ). There can be only one checking account for each account number. Remember since accountNumber is a private member in BankAccount, it must be changed through a mutator method. 5. Write a new instance method, withdraw, that overrides the withdraw method in the superclass. This method should take the amount to withdraw, add to it the fee for check clearing, and call the withdraw method from the superclass. Remember that to override the method, it must have the same method heading. Notice that the withdraw method from the superclass returns true or false depending if it was able to complete the withdrawal or not. The method that overrides it must also return the same true or false that was returned from the call to the withdraw method from the superclass. 6. Compile and debug this class. Use the AccountDriver class to test out your classes. If you named and created your classes and methods correctly, it should not have any difficulties. If you have errors, do not edit the AccountDriver class. You must make your classes work with this program
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
