Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MAIN CLASS public class Main{ public static void main(String[] args){ System.out.println(*** Test Savings Accounts ***); //create a SavingsAccount. Account #1001 and interest rate is 0.11

MAIN CLASS

public class Main{

public static void main(String[] args){

System.out.println("*** Test Savings Accounts ***");

//create a SavingsAccount. Account #1001 and interest rate is 0.11

SavingsAccount sa1 = new SavingsAccount(1001,0.11);

System.out.println("The interest on Account# " + sa1.getAccountNumber() + " is:");

System.out.println(sa1.getInterest());

sa1.deposit(1000); //deposit some amount

System.out.println("The balance of Account# " + sa1.getAccountNumber() + " after depositing 1000 is:");

System.out.println(sa1.getBalance());

sa1.applyInterest(); //Apply Interest

System.out.println("The the new balance for Account# " + sa1.getAccountNumber() + " after applying interest is: ");

System.out.println(sa1.getBalance());

//*******************

//create a SavingsAccount. Account #1002 and interest rate is 0

SavingsAccount sa2 = new SavingsAccount(1002,0);

System.out.println("The interest on Account# " + sa2.getAccountNumber() + " is:");

System.out.println(sa2.getInterest());

sa2.deposit(2000); //deposit some amount

System.out.println("The balance of Account# " + sa2.getAccountNumber() + " after depositing 2000 is:");

System.out.println(sa2.getBalance());

sa2.applyInterest(); //Apply Interest

System.out.println("The the new balance for Account# " + sa2.getAccountNumber() + "after applying interest is: ");

System.out.println(sa2.getBalance());

System.out.println("*** Test Checking Account ***");

//create a ChekingAccount. Account #1001 and orverdraft limit is 1800

CheckingAccount ca1 = new CheckingAccount(1003,1800);

ca1.deposit(2000); //deposit some amount

System.out.println("The overdraft limit for Account# " + ca1.getAccountNumber() + " is:");

System.out.println(ca1.getOverDraftLimit());

//update the overdraft limit of account 1003 to be 2800

ca1.updateOverDraftLimit(2800);

System.out.println("The new overdraft limit for Account# " + ca1.getAccountNumber() + " after the update is:");

System.out.println(ca1.getOverDraftLimit());

}

}

ACCOUNT CLASS

public class Account

{

private double bal; //The current balance

private int accnum; //The account number

public Account(int a)

{

bal=0.0;

accnum=a;

}

public void deposit(double sum)

{

if (sum>=0)

bal+=sum;

else

System.err.println("Account.deposit(...): "

+"cannot deposit negative amount.");

}

public void withdraw(double sum)

{

if (sum>0)

bal-=sum;

else

System.err.println("Account.withdraw(...): "

+"cannot withdraw negative amount.");

}

public double getBalance()

{

return bal;

}

public int getAccountNumber()

{

return accnum;

}

public String toString()

{

return "Acc " + accnum + ": " + "balance = " + bal;

}

public final void print()

{

//Don't override this,

//override the toString method

System.out.println( toString() );

}

}

SAVINGSACCOUNT CLASS

public class SavingsAccount{

//add your instance variable interest here

public SavingsAccount(int num, double interest){

//your code here

}

//implement getInterest() here

//implement applyInterest() here

}

CHECKINGACCOUNT CLASS

public class CheckingAccount{

//instance variable overDraftLimit here

public CheckingAccount(int num, int overDraftLimit){

//your code here

}

//implement getOverDraftLimit() here

//implement updateOverDraftLimit(int newLimit) here

}

image text in transcribedWRITE THE CODE IN JAVA FOR AN UPVOTE

- Using the class as a base class, complete the two classes called and Both classes should inherit the Account class. - A object, in addition to the attributes of an object, should have: 1) An interest rate private variable of type double named 2) A method named . This method does not take any parameters, but it returns the interest rate on the account. 3) A method named applyInterest(). This method applies the interest rate to the account's balance and increases it. For example, if the interest rate is 0.4 and the balance is 1000 , calling this method should update the balance to 1400 . This method does not take any parameters and does not return anything. - A object, in addition to the attributes of an object, should have: 1) An overdraft limit private variable of type integer named 2) A method which returns the overdraft limit of the account. The method does not take any parameters but it return the overdraft limit. 3) A method to update the overdraft limit on the account. This method takes an integer, but it does not return anything. Hints: - Note that the balance of an account may only be updated through the - The and classes should not need to be modified at all. - Test your code using the class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions