Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Java /* Account class. This class allows deposits and withdrawals but no overdraft limits or interest rates. */ public class Account { private double balance;

Java

/* Account class. This class allows deposits and withdrawals but no overdraft limits or interest rates. */ public class Account { private double balance; //The current balance private int acctNum; //The account number public Account() { balance = 0.0; acctNum = 0; } public void deposit(double amt) { . . . // add the amt to the balance only if positive } public void withdraw(double amt) { . . . // subtract the amt from the balance only if positive } public double getBalance()// should return the balance {. .. } public double getAccountNumber()// should return the account number {. . . } public void setBalance(double b)// should set the balance {. .. } public void setAccountNumber(int accn)// should set the account number {. . . } public String toString() // override it, by returning the account info {. . . } public final void print() { //Don't override this, override the toString method above System.out.println( toString() ); } }

Look at the Account class above and write a main method in a different class Bank to briefly experiment with some instances of the Account class. Using the Account class as a base class, write two derived classes called SavingsAccount and CheckingAccount. A SavingsAccount object, in addition to the attributes of an Account object, should have an interest variable (2%) and a method which adds interest to the account after each deposit. A CheckingAccount object, in addition to the attributes of an Account object, should have an overdraft limit variable ($50). Ensure that you have overridden methods of the Account class as necessary in both derived classes. Now create a Bank class with a main method, an object of which contains an arrayList of Account objects. Accounts in the array could be instances of the SavingsAccount class, or the CheckingAccount class. Create some test accounts (some of each type). Hints: Note that the balance of an account may only be modified through the deposit(double) and withdraw(double) methods. Be sure to test what you have done after each step. A sample run: What is your bank type (Checking or Savings): C What do you like to do (Deposit or Withdraw): D What is the amount: 1000 Your checking balance is 1000 What is your bank type (Checking or Savings): S What do you like to do (Deposit or Withdraw): D What is the amount: 2000 Your interest is 40 Your savings balance is 2040 What is your bank type (Checking or Savings): C What do you like to do (Deposit or Withdraw): W What is the amount: 1025 Your overdraft is 25 Your checking balance is -25 What is your bank type (Checking or Savings): S What do you like to do (Deposit or Withdraw): W What is the amount: 1500 Your savings balance is 540

Need all classes to execute and get output above

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions