Homework answers / question archive /
You were asked to create aBelow are the specifications of the applicationCreate aClass Date• day• year n online banking system application
You were asked to create aBelow are the specifications of the applicationCreate aClass Date• day• year n online banking system application
Computer Science
Share With
You were asked to create aBelow are the specifications of the applicationCreate aClass Date• day• year n online banking system application. package using the URL: bcit.ca/comp1451/assignment01 In the package add the following classes
This class has the following fields
- • month
-
- • A hash map with the key being the month number and the value is the month name
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,
- o field day mutator will use the passed parameter if it was between 1 and 31 inclusive. 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.
- o Field month mutator 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.
- o Field year mutator 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 from 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 Customer
This class have the following fields
- • name
- • address
- • date of birth (Date object)
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. Mutoators of String fields 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 "name cannot be null or an empty String" or "address cannot be null or an empty String"
- • Accessors for all 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 TransactionRecord
This class has the following fields
- • amountInCad of type double
- • transaction date 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( 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.
- o The mutator of the account number field will validate the passed parameter and uses 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.
- o The mutator of the amount field will validate the passed parameter and use it only if it was not negative or 0. If the passed parameter was negative or 0 an IllegalArgumentException will be thrown with a message to explain the problem.
- o 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.
- o 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 the value 1000 for example. Increment the static variable in the private method. Finally concatenate the static variable to a string and 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 not 0 or a negative number it will add it to the balance, the method will return true if the deposit was successful. If the passed parameter was negative or 0, the method will display the message ("invalid deposit amount") and the method will return false.
- • Method with the following signature:
public boolean withdraw(double amount)
The method validates the parameter, if it was positive and less than or equal to the balance, the parameter will be deducted from the balance and the boolean value true will be returned. If the parameter was negative or 0 or the balance will fall below 0 after the subtraction, the message " invalid amount" or "insufficient funds" will be displayed and the method will return false
- • A method to add a Transaction object to the ArrayList
- • A method to display the information of all the TransactionRecord objects.
- • 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 by calling the appropriate set method. The constructor also creates the hash Map
- • An accessor method for bankName field.
- • A mutator method for bankName 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 or it wasn't already in the hash map.
- • Method to return an account from the collection. The method signature is:
public Account getAccount(String accountNumber)
The method will take the account number.
- o If the number was not null and it is 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.
- o If the parameter was null an IllegalArgumentExeption will be thrown with a proper error message.
- o If the account number valid but 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.
- o If the account was not found a message will be displayed. And the loop will terminate
- o 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:
- o The method will ask the user for the amount and attempt to make the transaction, if the result of the transaction was true i.e. successful transaction, the method will ask the user to enter a day a month and a year value and it will create a Date object using these values.
- o A TransactionRecord object will be created and added to the ArrayList of that account.
- o If the transaction result was false(unsuccessful transaction), the loop will terminate.
- o If the user chose (Show Transactions ) , all Transaction records of that account will be displayed.
- o 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 for Date class. Create at least a positive and a negative test method for each method in class Date. Test only the methods that modifies Date class values
Marks will be given for:
- • Programming style. Your project uses correct style and this includes comments, indentation, correct use of naming conventions, using symbolic constant etc.
- • Correctness and completeness - code meets the requirements listed above.