Design and write 3 classes account,checking account,saving


Design and write 3 classes - Account, CheckingAccount, and SavingsAccount. Have CheckingAccount and SavingsAccount inherit from Account. In Account, you should include an account number, an account balance, a deposit and toString method, and an abstract withdraw method. Since deposits work the same way in both child classes, make sure they cannot override it. The constructor should only take an initial deposit and generate a random 5 digit account number. The toString should display the account number and the balance. Use a NumberFormat object to format the balance.

In the CheckingAccount class add a minimum balance and overdraft fee. Implement the withdraw method so that overdrafts are allowed, but the overdraft fee is incurred if the balance drops below the minimum balance. Override the toString method to display everything the Account toString displays plus the minimum balance. Use the parent class toString to do most of the work. You should not need a NumberFormat object in this method.

In the SavingsAccount class add an annual interest rate and a method to recalculate the balance every month. Since the interest rate is annual, make sure to calculate the interest accordingly. Override the toString method to display everything the Account toString displays plus the interest rate. Like the CheckingAccount toString, you should use the parent class to do most of the work and should not need a NumberFormat object. 

Create a driver class to instantiate and exercise each of the account types.


// ***************************************************************
// AccountDriver.java 
// ***************************************************************
public class AccountDriver
{
public static void main(String[] args) 
{

CheckingAccount B = new CheckingAccount(5430);
SavingsAccount C = new SavingsAccount(3043);

//print whatever is in the toString line
System.out.println(B);
System.out.println(C);


B.withdraw(6000);
C.withdraw(5000);

System.out.println(B);
System.out.println(C);
}
}


// ***************************************************************
// SavingsAccount.java 
// Represents a savings account 
// ***************************************************************
import java.text.NumberFormat;

public class SavingsAccount extends Account
{
private double interestRate = 1.5;

//-----------------------------------------------------------------
// Constructor: Sets up this savings account using the specified information
//-----------------------------------------------------------------
public SavingsAccount(int initialDeposit)
{


//-----------------------------------------------------------------
//withdraws amount from the account if there is enough to draw against
//If balance is less than the withdrawal request, display a message stating 
//"Withdrawal amount is greater than balance. Withdrawal denied. Go rob another bank!"
//-----------------------------------------------------------------
public void withdraw(int amount)
{


//-----------------------------------------------------------------
// Recalculates the balance by applying interest monthly
//-----------------------------------------------------------------
public void recalculateBalance()
{
balance *= (1 + ((interestRate / 100) / 12));

////Whatever the account toString displays + interest rate
public String toString()
{

}
}

// ***************************************************************
// CheckingAccount.java 
// Represents a checking account
// 
// ***************************************************************
public class CheckingAccount extends Account
{
private final int MINIMUM_BALANCE = 100;
private final int OVERDRAFT_FEE = 25; 
//-----------------------------------------------------------------
// Constructor: Sets up this checking account using the specified
// information
//-----------------------------------------------------------------
public CheckingAccount(int initialDeposit)
{
super(initialDeposit);

//-----------------------------------------------------------------
// withdraws amount from the account. If an overdraft occurs
// a fee is deducted from the account
//-----------------------------------------------------------------
public void withdraw(int amount)
{

}
//Whatever the account toString displays + minimum balance 
public String toString()
{

}

}

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: Design and write 3 classes account,checking account,saving
Reference No:- TGS0134282

Expected delivery within 24 Hours