Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Account class is public class Account { private int id; protected double balance; private double annualInterestRate; private Date dateCreated; Account(){ id = 0; balance =

image text in transcribed

Account class is

public class Account { private int id; protected double balance; private double annualInterestRate; private Date dateCreated; Account(){ id = 0; balance = 0; annualInterestRate = 0; dateCreated = new Date(); } Account(int ID, double Balance){ id = ID; balance = Balance; dateCreated = new Date(); }

public int getId() { return id; }

public void setId(int id) { this.id = id; }

public double getBalance() { return balance; }

public void setBalance(double balance) { this.balance = balance; }

public double getAnnualInterestRate() { return annualInterestRate; }

public void setAnnualInterestRate(double annualInterestRate) { this.annualInterestRate = annualInterestRate; }

public Date getDateCreated() { return dateCreated; } public double getMonthlyInterestRate() { return annualInterestRate/12.0; } public void withdraw(double amount) { balance = balance - amount; } public void deposit(double amount) { balance = balance + amount; } }

tester class is

public class Prob1_Tester { public static void main (String[] args) { CheckingAccount account = new CheckingAccount(1122, 1000.0, 5000.0); printCheckingInfo(account); account.withdraw(2000.0); printCheckingInfo(account); account.withdraw(5000.0); printCheckingInfo(account); account.setOverdraftLimit(2000.0); printCheckingInfo(account); account.withdraw(1001.0); printCheckingInfo(account); account.withdraw(999.0); printCheckingInfo(account); SavingsAccount sAccount = new SavingsAccount(1122, 1000.0); printSavingsInfo(sAccount); sAccount.withdraw(1001.0); printSavingsInfo(sAccount); sAccount.withdraw(999.0); printSavingsInfo(sAccount); } public static void printCheckingInfo( CheckingAccount acnt) { System.out.printf("Bal: $%4.2f, overdraft limit: $%4.2f ", acnt.getBalance(), acnt.getOverdraftLimit()); } public static void printSavingsInfo( SavingsAccount acnt) { System.out.printf("Bal: $%4.2f ", acnt.getBalance()); }

}

****************** print out********

Bal: $-1000.00, overdraft limit: $5000.00

Bal: $-1000.00, overdraft limit: $5000.00

Bal: $-1000.00, overdraft limit: $2000.00

Bal: $-1000.00, overdraft limit: $2000.00

Bal: $-1999.00, overdraft limit: $2000.00

Bal: $1000.00

Bal: $1000.00

Bal: $1.00

Name the two subclasses: CheckingAccount and SavingsAccount. The CheckingAccount class should have at least 3 constructors to be consistent with the superclass. However, you will only provide one. This one constructor should accept: id, balance, and overdraft limit. It should utilize a superclass constructor. Similar for SavingsAccount, supply one constructor that accepts id and balance and utilizes a superclass constructor. Make sure the checking account subclass has methods to get and set the overdraft limit The problem says, "a checking account has an overdraft limit." This is the way this should be handled a. Override the withdraw method. Only allow a withdrawal if the balance does not go below the negative of the overdraft limit. Example: Balance $1000, OverdraftLimit- $5000, Cannot withdraw $7000 (Balance would be -6000 which is less than -5000). Can withdraw S5900 (Balance would be -4900 which is greater than -5000) b. Technically, I guess you should also override the setBalance method to work in the same way to be consistent, but you do not need to do that. I don't think the class should even have this method. The balance should be read-only, and modified only through the methods withdraw and deposit. The problem says, "a savings account cannot be overdrawn." This simply means that the balance can never be negative. Similar to the checking account except that we don't need the overdraft limit. Write a test class AccountTester in package prob1. which is exactly as shown belo (copy/paste). Your code w should work perfectly with this test 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

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

What is terminal velocity? How is it determined?

Answered: 1 week ago

Question

What is a niche market?

Answered: 1 week ago

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago