QuestionQuestion

You were asked to create an online banking system application.Below are the specifications of the application

Create a package using the assignment01

In the package add the following classes

Class Customer

This class have the following fields
• name
• address
• date of birth

The class provides the following functionality

• A constructor that takes parameters to initialize all fields, the constructor calls the appropriate mutators to validate the parameters and set the fields properly

• Mutators for all the fields.

Fields of type mutators will use the passed parameter if it was not null or an empty String.

If the passed parameter was null or an empty String “” an IllegalArgumentException will be thrown with a message to explain the problem

• Accessors for all the fields

• A method to format the name properly, the first letter should be upper case and the rest of the name should be lower case regardless of how it was provided.

Keep in mind the name should be formatted properly and assigned to its respective field. the method signature is : public String formatName(String word)

• A method to display all the information of the customer in an organized format. Note that the name should be formatted properly

Class Date

This class has the following fields

• day

• month

• year

• A hash map with the key being the month number and the value is the month name for example: monthNames < Integer , String >

The class provides the following functionality

• A constructor that takes three parameters to initialize the fields day, month and year.

The constructor will call the set methods to validate the passed parameters and initialize the fields properly.

The constructor will create the hash map and call a private method to load the hash map with the months names and numbers

• The first three fields have a properly named accessors

• The first three fields have a properly named mutators, the mutator of the day will use the passed parameter if it was between 1 and 31.

If the passed parameter was invalid the field will be set to 1.

For the sake of this assignment we will assume that all months have 31 days.

The mutator of month field will use the passed parameter if it was between 1 and 12 inclusive.

If the passed parameter was invalid the field will be set to 1.

The mutator of the year field will accept the parameter if it was between 1900 and the current year inclusive.

If the passed parameter was invalid the year will be set to 1900

• A private method to populate the hash map with the month names and numbers.

This method will be called form the constructor

• A method to return a String of the date in the following format dd/month name /yyyy.

If the day value consisted of one digit, it will be proceeded by 0, for example day 3 of month 3 of year 2013 will be displayed as: 03/March/2013, otherwise it will be displayed as follows:   day 11 of month 3 of year 2013 will be displayed 11/March/2013

Class TransactionRecord

This class has the following fields

• amount of type double

• date issued of type Date

• accountNumber of type String

• transactionType.   One of two values (withdraw, deposit)

The class provides the following functionality

• Constructor that takes parameters to initialize fields amount, date, accountNumber and transaction type.

The constructor calls the mutators to initialize the fields properly.

• Properly named accessor for each field.

• Properly named mutator for each field, the mutator of the account number field will validate the passed parameter and use it only if was not null or an empty String, if the passed parameter was null or an empty String an IllegalArgumentException will be thrown with a message to explain the problem.

The mutator of the amount field will validate the passed parameter and use it only if it was positive.

If the passed parameter was negative an IllegalArgumentException will be thrown with a message to explain the problem.

The mutator of the Date type field will validate the parameter and uses it if it was not null. If the passed parameter was null IllegalArgumentException will be thrown with a message to explain the problem.

The mutator of transaction type field will validate the passed parameter and uses it only if it was one of two values, withdraw or deposit.

If the passed parameter had value other than the specified an IllegalArgumentException will be thrown with a message to explain the problem

• A method which returns a String that contains the account number, type of transaction, amount and the date of the Transaction

Class Account

The class has the following fields

• customer of type Customer

• account number (String)

• the date the account was created of type Date

• balance of type double

• ArayList of TransactionRecord objects

The class will provide the following functionality

• Constructor that takes parameters to initialize customer, the date the account was created and the balance.

The constructor will call the mutators to initialize the fields.

The constructor will also create the array list and will call a private method to create a unique number and assign it to the account number field.

• A private method to create an account number and assign it to the field accountNumber, keep in mind that each account object should have a unique account number.

One way of doing that is by creating a static variable, setting it to a value, 1000 for example and incrementing that static variable in the private method.

Finally assign the result to the field account number. Don’t forget to call the private method in the constructor.

• Accessors for all fields (instance variables only).

• Method that have the following signature public boolean deposit (double amount)

The method checks the parameter and if it is positive it will add it to the balance, the method will return true if the deposit was successful.

If the passed parameter was negative, the method will display a message to state that the amount was invalid and the method will return false


• Method with the following signature: public boolean withdraw(double amount)

The method checks the parameter, if it is positive and less than or equal to the balance it will be subtracted from the balance and true will be returned.

If the parameter was negative or the result of the subtraction will be negative, a message stating that the amount was invalid will be displayed and the method will return false

• A method to add a Transaction object to the arrayList

• A method that takes a String which is the customer name loops through the collection and displays all transactionRecord details

• A method that displays the following information of the account

The customer full name

The account number

The balance

The date the account was created

Class Bank

The class has the following fields

• bankName of type String

• HashMap of Account objects.The key of the hash map is the account number and the value is the account object

The class provides the following functionality:

• Constructor that accepts a parameter to initialize the bank name field by calling the appropriate set method.

The constructor also creates the hashMap

• An accessor method to the String field

• A mutator method to the String field, the mutator will use the passed parameter if it was not null or an empty String.

If the passed parameter was null or an empty String an IllegalArgumentException will be thrown with a message to explain the problem

• Method addAccount() the method signature is as follows: public void addAccount(Account toadd)

The method will take an account object and adds it to the hashMap only if it was not null

• Method to return an account from the collection. The method signature is: public Account getAccount(String accountNumber)

The method will take the account number.

If the number was not null and it was found in the hashMap, the method will display the details of the account and returns the account object associated with the number from the collection.

If the parameter was null an IllegalArgumentExeption will be thrown with a message to explain the problem.

If the account number was not found in the collection, the method will display a message stating that account number was not found in the collection.

• A method that takes the customer name as a parameter and displays the account details including all transaction record details of that customer, the method will display an error message if the customer was not found in the collection.

Here is the method signature: public void showTransactions(String name)

• Method to display all the bank account numbers in the collection.

Here is the method signature: public void displayAccountNumbers()

• Method makeTransaction() the method signature is as follows: public void makeTransaction()

The method creates a loop to ask the user for the account number and gets the account from hash map.

If the account was not found a message will be displayed.

And the loop will end

If the account was found the method then will display a list of possible transactions

1. Deposit

2. Withdraw

3. Show Transactions

The method will ask for the transaction type and get the choice number from the user.

If the choice was one or two the method will ask the user for the amount
The method will attempt to make the transaction, if the result of the transaction was true the method then will ask the user to enter a day a month and a year value and it will create a Date object using these values.


Finally a transactionRecord object will be created and added to the arrayList of that account If the result was false, the loop will end

If the user chooses number 3 then the method will ask for the user name and invoke method showTransactions () using the given name

After the transaction is done the user will be asked if he/she wants to make another transaction if the answer was yes the same process will be repeated, if no then the loop will end.

Class Driver

Add the main method (public static void main(String[] args). In this method do the following:

• Create 4 Customer objects and use them to create 4 Account objects.

• Create a Bank object and add the account objects to your hashMap.

• Call method displayAccountNumbers() then call method makeTransaction() .

Testing

Create a junit testing class and test each mutator and method that can be tested in class Date. Create at least two tests for each method (negative and positive test) if applicable.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

package assignment01;

import java.util.HashMap;
import java.util.Scanner;

/*
* Bank class
*/
public class Bank {

private String bankName;
private HashMap<String,Account> accounts;

public Bank(String bankName) {
setBankName(bankName);
this.accounts = new HashMap<String,Account>();
}

public String getBankName() {
return bankName;
}

public void setBankName(String bankName) {
if (bankName == null)
throw new IllegalArgumentException("Error: null bankName argument");
else if (bankName.equals(""))
throw new IllegalArgumentException("Error: empty bankName argument");
this.bankName = bankName;
}

public void addAccount(Account toadd) {
if (toadd == null)
throw new IllegalArgumentException("Error: null account argument");
else
this.accounts.put(toadd.getAccountNumber(), toadd);
}

public Account getAccount(String accountNumber) {
if (accountNumber == null)
throw new IllegalArgumentException("Error: null accountNumber argument");
else if (accountNumber.equals(""))
throw new IllegalArgumentException("Error: empty accountNumber argument");
else {
if (accounts.containsKey(accountNumber)) {
Account account = this.accounts.get(accountNumber);
account.display();
return account;
} else {
System.out.println("Error: Account number " + accountNumber + " not found!");
return null;
}
}
}

public void showTransactions(String name) {
for (Account account: accounts.values()) {
if (account.getCustomer().getName().equals(name)) {
account.displayTransactions(name);
return;
}
}
System.out.println("Error: Account name " + name + " not found!");
}

public void displayAccountNumbers() {
if (accounts.isEmpty()) {
System.out.println("No account numbers found");
return;
}
System.out.println("Account numbers:");
for (String accountNumber: accounts.keySet()) {
System.out.println(accountNumber);
}
}

public void makeTransaction() {
Scanner s = new Scanner(System.in);
while (true) {
System.out.print("Enter account numb...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

50% discount

Hours
Minutes
Seconds
$60.00 $30.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats