Question: Week 10 Class Account Problem 2: You are given the class Account with predefined methods for bank account. It already has methods to display the

Week 10 Class Account

Problem 2:

You are given the class Account with predefined methods for bank account. It already has methods to display the balance and methods to withdraw and deposit some amount.

You need to create a subclass called SavingsAccount. Your SavingsAccount class should override the deposit method, so that when a user deposits an amount in the savings account, the bank will add additional 10% to the amount.

You are given a testAccount class which asks the user what account it want to create. In the testAccount class, add java code to do the following things in a sequential order:

create a new savings account object (for choice 2).

ask the user to enter an initial balance which should be greater than 50. If the entered amount is less than 50, the program will ask the user to enter another amount. This continues until an amount greater than 50 is entered.

Set the balance of the savings account object by calling the setBalance() method.

Ask the user to deposit an amount. Deposit that amount and display the balance of the account.

Turn in the SavingsAccount.java and testAccount.java.

Sample Output:

Welcome. Which account do you want to create?

1. Normal 2. Savings

Enter choice: 1

Balance - 0.0

Enter amount to deposit: 500

Balance - 500.0

Welcome. Which account do you want to create?

1. Normal 2. Savings

Enter choice: 2

Enter initial balance: (>$50) - 10

Balance should be greater than 50

Enter initial balance: (>$50) - 900

Balance - 900.0

Enter amount to deposit: 30

Balance - 933.0

This is given for problem 2:

public class Account { protected double balance;

public Account() { balance = 0; }

public void setBalance(double amt) { balance += amt; }

public void deposit(double amt) { balance += amt; }

public void withDraw(double amt) { balance -= amt; }

public void displayBalance() { System.out.println("Balance - " + balance); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!