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

Java Homework: 1. A Bank Account Class 1. Write an Account class as described be

ID: 662673 • Letter: J

Question

Java Homework:

1. A Bank Account Class

1. Write an Account class as described below. Note that you won't be able to test your methods until you write the ManageAccounts class in Question

2. a. Define class variable of balance, name, and accNum. This requires defining an appropriate visibility and data type for each variable. b. Write methods withdraw, deposit, and getBalance. c. Write a toString method which returns a string containing the name, account number, and balance for the account. d. Write a method chargeFee which deducts a service fee ($10) from the account. e. Modify chargeFee so that instead of returning void, it returns the new balance. Note that you will have to make changes in two places. f. Write a method changeName which takes a string as a parameter and changes the name on the account to be that string.

2. Write a class ManageAccounts doing the following.

1. Create account1 for Sally with $1000 for account number 1111.

2. Create account2 for Joe with $500

3. Deposit $100 to Joe's account

4. Print Joe's new balance (use getBalance())

5. Withdraw $50 from Sally's account

6. Print Sally's new balance (use getBalance())

7. Charge fees to both accounts

8. Change the name on Joe's account to Joseph

9. Print summary for both accounts

3. Modify ManageAccounts 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.

4. Compile and run the program.

5. Draw a UML class diagram and sequence diagram. It must be drawn using a computer-aided tool (e.g., Enterprise Architect, Microsoft Visio)

Example Output ManageAccounts Trace: 940.0 590.0 Name: Sally Account number: 1111 Balance: $940.00 Name: Joseph Account number: 1112 Balance: $590.00 BUILD SUCCESSFUL (total time: 0 seconds)

Explanation / Answer

Class : Account


public class Account
{
   public String name;
   public double balance;
   public int accNum;
  
  
   public void withdraw(double amt)
   {
       balance=balance-amt;
      
   }
  
   public void deposit(double amt)
   {
       balance=balance+amt;
      
   }
  
   public double getBalance()
   {
       return balance;
   }
  
   public String toString()
   {
       String out="Name : "+ name + " Account Number : " + accNum + " Balance : $"+balance;
      
       return out;
   }
  
   public double chargeFee()
   {
       balance=balance-10;
      
       return balance;
   }
  
   public void changeName(String newName)
   {
       name=newName;
   }
  
}

Class : ManageAccount


public class ManageAccounts
{
   public static void main(String args[])
   {
       Account account1 = new Account();
      
       Account account2 = new Account();
      
       account1.name="Sally";
       account1.balance=1000;
       account1.accNum=1111;
      
       account2.name="Joe";
       account2.balance=500;
      
       account2.deposit(100);
       System.out.println("Joe's balance = $"+account2.getBalance());
      
       account1.withdraw(50);
      
       System.out.println("Sally's balance =$"+account1.getBalance());
      
      
       System.out.println("Joe's balance = $"+account1.chargeFee());
      
       System.out.println("Sally's balance =$"+account2.chargeFee());
      
       account2.changeName("Joseph");
      
       System.out.println(account1.toString());
       System.out.println(account2.toString());
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote