A Bank Account Class

This lab gives you practice with writing and calling simple methods. It also gives you practice with using methods to access private data members.

  1. File Account.java contains a partial definition for a class representing a bank account. 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.
    1. Fill in the code for method printSummary, which should print the name, account number, and balance for the account.
    2. Fill in the code for method chargeFee, which should deduct a service fee from the account. If the balance is $1000 or more, no fee should be charged, but if it is less than $1000, $10 should be deducted from the balance.
    3. Modify chargeFee so that instead of returning void, it returns the new balance. Note that you will have to make changes in two places.
    4. 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 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.

Go back to lab1 index page