Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A Bank Account Class 1. Recreate the code listed below. Save it to your directory and study it to see what methods it contains. Then
A Bank Account Class 1. Recreate the code listed below. Save it to your directory and study it to see what methods it contains. Then complete the Account class as described below. Note that you won't be able to test your methods until you write ManageAccounts in question #2. a. Fill in the code for method to String, which should return a string containing the name, account number, and balance for the account. b. Fill in the code for method chargeFee, which should deduct a service fee from the account. c. Modify chargeFee so that instead of returning void it returns the new balance. Note that you will have to make changes in two places. d. Fill in the code for method changeName which takes a string as a parameter and changes the name on the account to be that string. 2. File ManageAccounts.java contains a shell program that uses the Account class above. Save it to your directory, and complete it as indicated by the comments. 3. Modify Manage Accounts so that it prints the balance after the calls to chargeFees. Instead of using the getBalance method like you did after the deposit and withdrawal, use the balance that is returned from the chargeFees method. You can either store it in a variable and then print the value of the variable, or embed the method call in a println statement. 28 // Account.java 11 A bank account class with methods to deposit to, withdraw from, // change the name on, charge a fee to, and print a summary of the account. public class Account 1 private double balance; private String name; private long acctNum; //---- //Constructor initializes balance, owner, and account number //--- public Account (double initBai, String owner, long number) balance = initBal; name = owner; acctNum = number; } // - // Checks to see if balance is sufficient for withdrawal. // If 30, decrements balance by amount; if not, prints message. // - public void withdraw (double amount) if (balance >= amount) balance -= amount; else System.out.println("Insufficient funds"); } // Adds deposit amount to balance. //----- public void deposit (double amount) 1 balance += amount; } // - // Returns balance. //------- public double getBalance () 1 return balance; } // Returns a string containing the name, account number, and balance. //---- public String toString() 1 } // Deducts $10 service fee //-- public void chargeFee () 1 } // - // Changes the name on the account //----- public void changeName (String newName) 1 } } ManageAccounts.java Use Account class to create and manage Ginger and Joe's bank accounts public class ManageAccounts 1 public static void main(String[] args) 1 Account accti, acct2; //create accounti for Ginger with $1000 accti = new Account (1000, "Ginger", 1111); //create account2 for Joe with $500 //deposit $100 to Joe's account //print Joe's new balance (use getBalance ()) //withdraw $50 from Ginger 's account //print Ginger's new balance (use getBalance()) // charge fees to both accounts // change the name on Joe's account to Joseph //print summary for both accounts } }
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