In this assignment you use an abstract class to represent a


Programmers often develop different types of accounts to provide access to a program for a variety of users. The structure of each account is formatted based on the needs of the user and how the program will be used. One type of account is a banking account, which can be used to manage personal financial information. The concrete classes of this type of account contain specific details pertinent to the user and the account, such as the amount of money in the account.

In displaying monetary values, amounts of money are typically written as the amount of dollars and cents with a decimal point. They represent exact quantities. You'll recall that the Java types doubleand floatare inherently inexact. It is always an error, and sometimes a very serious error, to use inexact numeric types for money.

In this assignment you use an abstract class to represent a bank account and concrete classes to represent a checking account and a savings account.

Because the amount of money in these accounts must be exact, you must store all monetary units as intvariables. Your program must keep all monetary values as cents, although the users are not required to enter monetary values in cents. You must create a separate method to convert from dollars and decimal points into an exact number of cents. For example, if the user enters $12.25, this method returns the value 1225.

Create the BankAccountabstract class, with these methods:

- public void deposit(int cents)-Adds money to the account by taking in the number entered by the user and increasing the amount of money in the account by the specified amount (in cents).

- public boolean withdraw(int cents)-Takes money out of the account by taking in the number entered by the user and decreasing the amount of money in the account by the specified amount (in cents). Returns falseif there are insufficient funds in the account.

- public int balance() -Returns the amount of money (in cents) in the account.

- public static boolean transfer(int cents, BankAccountfromAccount, BankAccounttoAccount)-Withdraws money from fromAccountand puts it in toAccount. Returns falseif there are insufficient funds in the fromAccount.

Now create a SavingsAccountclass that extends BankAccount. This new class does not add any new functionality.

Create a CheckingAccountclass that extends BankAccount. Add the following public method:

- public String writeCheck(int cents)-Withdraws the given amount. If there are insufficient funds, this method returns the string INSUFFICIENT FUNDS. If there are sufficient funds, this method returns the dollar amount (for any amount less than one million dollars) as a sequence of uppercase words. For example, ONE HUNDRED SEVEN DOLLARS AND 33 CENTS. When expressing dollars and cents in words, use the word ANDonly before the cents. For example, do not say ONE HUNDRED AND SEVENDOLLARS.

Notes:

- By now you should be used to the idea of TDD-writing the tests first. Continue to do so in this assignment. Perform tests to ensure that, when a method fails because of insufficient funds, the account balances remain unchanged.

- It is good programming style to compose a program from a larger number of small, simple, and relatively independent methods rather than fewer, complex, and tightly-coupled methods. In this assignment, you could put the code for converting dollar amounts into words into the writeCheckmethod, but this would mean:

o You won't ever be able to convert dollars into words without writing a check.
o You won't ever be able to write a check in a different format.
o Your test methods become significantly more complicated.

To avoid these problems, write a separate method (for example, dollarsToWords) that is called from the writeCheckmethod.

- Use the mod (%) and integer division (/) operators; amount%10gives you the last (rightmost) digit of an integer number, while amount/10discards that last digit.

Finally, write a class Bank, containing a mainmethod, to interact with a user who wants to examine balances, perform deposits, withdrawals, and transfers, and write checks.

- Make your program easy to use; write instructions for the program to print out for the user. The instructions tell the user how to perform the various banking operations, as well as how to quit.
- Since the user must enter monetary amounts, you must use a Scannersimilar to the Animal Characteristics Application you previously created.
- Do not require the user to enter monetary amounts in cents. Let the user enter amounts in the following formats:

o12.34
o$12.34
o12.
o12

Your program must have the capability to convert inputs to and from integer cent amounts. Write a method to handle this task. Test this part thoroughly.

- When printing monetary amounts for the user (when he/she asks for the balance of an account), your program must display the amount of money in the account in the following format:

o$12.34

Your program must have the capability to convert outputs from integer cent amounts to dollars. Write a separate method to handle this task.

In your main method, create one SavingsAccount and one CheckingAccount, both with a balance of zero cents. You do not need to write a method to create an account or input any personal account information like name, address, phone number, etc. You do not have to keep track of balances between runs of the program.

When submitting your Application, include screenshots of your program running. Take screenshots demonstrating how your program handles different formats of monetary input. Take screenshots showing two deposits into each of the two accounts, one withdrawal from each of the accounts, one attempt to withdraw more money than one of the accounts contains, and one transfer from one account to the other. Take screenshots showing the balances of each account after each of these transactions. Include screenshots of your program being tested with JUnit.

Save your NetBeans Project and screen shots of the working program as a ".zip" file.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: In this assignment you use an abstract class to represent a
Reference No:- TGS01592393

Now Priced at $40 (50% Discount)

Recommended (91%)

Rated (4.3/5)