2. Create a class Account that represents a banking account. The class has attri
ID: 3552436 • Letter: 2
Question
2. Create a class Account that represents a banking account. The class has
attributes owner, accountNo and balance. The constructor for the class
requires the name of the owner of the account and the initial deposit for the
account, which will be stored in the balance attribute. A static int variable is
used for accountNo, which is initially set to 12345. Each object of the
class Account is assigned its accountNo by adding 1 to the current value in
the static variable. Therefore, the first account will be assigned 12346 as its
accountNo.
The business rules for objects of class Account are:
An owner name can be changed
No method should allow the balance value to become negative
Only deposits and withdrawals can alter the value stored in balance,
and their amounts must be positive, that is you cannot deposit -
$10.00
Interest is always 5% per annum.
Following the business rules, create methods of deposit, withdrawal,
addInterest and appropriate get and set methods for the class. The toString
should display the accountNo and the balance.
Note: To format the balance so that it prints out with a $ in front of the
amount and to two decimal places, you can use class NumberFormat to do
this. You will need to
a. Firstly make an import declaration
import java.text.NumberFormat;
b. Add the following to your code
NumberFormat formatter =
NumberFormat.getCurrencyInstance ();
c. Call up the method format on the balance
formatter.format (balance);
Write a method called equals that compares two Account objects and
returns true if the objects have the same owner, otherwise the method
returns false.
Write a class TestAccount which creates an array of five different Account
objects, with at least two objects having the same owner values.
Systematically check the functionality of all methods of class Account
including the equals method to find out how many different accounts are
owned by the same person.
3. Using the class Account in question 2, derive two additional account types:
OnLineAccount and SavingsAccount, where OnLineAccount and
SavingsAccount inherit from Account.
In Account, change the visibility of all data to protected. Change the
withdraw method so that it becomes an abstract method. This action will
necessitate you declaring the class as abstract. Deposits should work the
same way in OnLineAccount and SavingsAccount so make sure they cannot
override their parent
Explanation / Answer
contact http://www.writingcentre.us/ to get the best result/grade, i have been using them for over 2years now they are really helpful
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.