Given: UML diagram of an Account object Below. Use Java progaramming Language. Note: The static variables/data fields and methods in UML class diagrams are underlined. Create an Account Object project. 1. Design an Account class and use the provided UML diagram to code the instance fields, constructors and methods. Note: The type of accounts are 1 (Savings) or 2 (Cheque) The constructor must assign the values of the parameters to the data fields/instance variables. The static field must be increased by one in the constructor. The setAccNumber() is a private void method. The account number must consist of the first 3 letters of the name of the account holder, the digit indicating the type of account and #-character and a 3-digit random value. This method must be called from the constructor. The makeDeposit() method must add the amount received as a parameter to the balance if the value received is not a negative value. The withdrawAmount() method must check whether the balance allows for the amount to be withdrawn. There must always be a minimum amount of R 100.00 in an account. If there is not enough money in the account to do the transaction, return the boolean value of false, else return true and subtract the amount from the balance. The toString() method must compile a string to display all the attributes of the object on one line. Example: FRA1#534 Frank 1 R 600.00 Declare a static integer variable to count the number of Account objects being instantiated (created). Add code to both the constructors to increment the static variable when an object is instantiated. 2. Design a testAccounts class. Do the following: Declare an array called arrAccounts of 20 Account type objects in the main method. Write a static method in the test class called fillArray() to receive the array. See Par 9.10 and 9.11 – how to transfer objects to a static method in the main method. Use a while loop to enter the information (name of the account holder, type of account (1 or 2) and amount) of a number of accounts. For each account create an object and save the object in the array. Return the array to the main method. Call the static fillArray() method from the main method. Write another static method called displayArray() to receive the array and display a numbered list of the accounts using a for loop and the toString() method. In the main method, use a loop to do transactions. First, ask the user whether a transaction must be done or not (loop). If Yes call the displayArray() method to show the numbered list of accounts. Ask the user to enter the number of the account on the list. Then ask the type of transaction (W to withdraw or D for deposit) to be done and the amount. Call the relevant method to do the relevant transaction. If it is a withdrawal transaction and there is not enough money in the account, display a suitable message. Otherwise, display “Transaction done”. Display the accountholder’s updated balance using thegetBalance() method. Ask the user whether another transaction must be done. Keep on doing transactions until the user terminates the loop by indicating that there are no more transactions to be done.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Given: UML diagram of an Account object Below.
Use Java progaramming Language.
Note: The static variables/data fields and methods in UML class diagrams are underlined.
Create an Account Object project.
1. Design an Account class and use the provided UML diagram to code the instance fields, constructors and methods.
Note:
The type of accounts are 1 (Savings) or 2 (Cheque)
The constructor must assign the values of the parameters to the data fields/instance variables.
The static field must be increased by one in the constructor.
The setAccNumber() is a private void method. The account number must consist of the first 3 letters of the name of the account holder, the digit indicating the type of account and #-character and a 3-digit random value. This method must be called from the constructor.
The makeDeposit() method must add the amount received as a parameter to the balance if the value received is not a negative value.
The withdrawAmount() method must check whether the balance allows for the amount to be withdrawn. There must always be a minimum amount of R 100.00 in an account. If there is not enough money in the account to do the transaction, return the boolean value of false, else return true and subtract the amount from the balance.
The toString() method must compile a string to display all the attributes of the object on one line.
Example:
FRA1#534 Frank 1 R 600.00
Declare a static integer variable to count the number of Account objects being instantiated (created). Add code to both the constructors to increment the static variable when an object is instantiated.
2. Design a testAccounts class. Do the following:
Declare an array called arrAccounts of 20 Account type objects in the main method.
Write a static method in the test class called fillArray() to receive the array. See Par 9.10 and 9.11 – how to transfer objects to a static method in the main method.
Use a while loop to enter the information (name of the account holder, type of account (1 or 2) and amount) of a number of accounts. For each account create an object and save the object in the array. Return the array to the main method.
Call the static fillArray() method from the main method.
Write another static method called displayArray() to receive the array and display a numbered list of the accounts using a for loop and the toString() method.
In the main method, use a loop to do transactions.
First, ask the user whether a transaction must be done or not (loop). If Yes call the displayArray() method to show the numbered list of accounts.
Ask the user to enter the number of the account on the list.
Then ask the type of transaction (W to withdraw or D for deposit) to be done and the amount.
Call the relevant method to do the relevant transaction. If it is a withdrawal transaction and there is not enough money in the account, display a suitable message. Otherwise, display “Transaction done”.
Display the accountholder’s updated balance using thegetBalance() method.
Ask the user whether another transaction must be done.
Keep on doing transactions until the user terminates the loop by indicating that there are no more transactions to be done.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps