0% found this document useful (1 vote)
173 views1 page

MPL Assignmnts Quesitions

The document describes how to create an Account class with methods to get and modify a balance, along with subclasses for SavingsAccount and CheckingAccount. The Account class has a private balance attribute and public methods to deposit, withdraw, and get the balance. SavingsAccount extends Account and adds an interestRate. CheckingAccount extends Account and can have overdraft protection, overriding withdraw to check the balance first before allowing a withdrawal.

Uploaded by

Muhammad Khubaib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
173 views1 page

MPL Assignmnts Quesitions

The document describes how to create an Account class with methods to get and modify a balance, along with subclasses for SavingsAccount and CheckingAccount. The Account class has a private balance attribute and public methods to deposit, withdraw, and get the balance. SavingsAccount extends Account and adds an interestRate. CheckingAccount extends Account and can have overdraft protection, overriding withdraw to check the balance first before allowing a withdrawal.

Uploaded by

Muhammad Khubaib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

 Create the Account class in the file Account

a.    Declare one private object attribute: balance; this attribute will hold the current (or
"running") balance of the bank account. 
b.    Declare a public constructor that takes one parameter, initBalance, which populates the
balance attribute.
c.     Declare a public method getBalance that retrieves the current balance. 
d.    Declare a public method deposit that adds the amount parameter to the current
balance. The deposit method is to always return true, meaning all deposits are
successful.
e.    Declare a public method withdraw that removes the amount parameter from the current
balance. The withdraw method is to check that the amount being withdrawn is not
greater than the current balance. If amt is less than balance, then subtract the amount
from the balance and return true; else, leave the balance alone and return false.

Create the Savings Account Subclass

a. The SavingsAccount class must extend the Account class.


b. It must include an interestRate attribute with type double.
c. It must include a public constructor that takes two
parameters: balance and interestRate. This constructor must pass
the balance parameter to the parent constructor by calling super(balance).
d. Override the withdraw method(Same as in parent class).

Create the Checking Account Subclass

a. The CheckingAccount class must extend the Account class.


b. It must include an overdraftProtection attribute with type double.
c. It must include one public constructor that takes one parameter: balance. This
constructor must pass the balance parameter to the parent constructor by
calling super(balance).
d. It must include another public constructor that takes two
parameters: balance and protect. This constructor must pass
the balance parameter to the parent constructor by calling super(balance) and set
the overdraftProtection attribute.
e. The CheckingAccount class must override the withdraw method. It must it perform
the following check: if the current balance is enough to cover the amount to
withdraw, then proceed as usual. If not then the whole transaction must fail with the
checking balance unaffected.

You might also like