Java program help.
This design will cover the key OOP concepts of: UML diagrams, classes, objects, attributes, methods, encapsulation, messages, inheritance, polymorphism, exceptions and association relationships. In terms of Java, you will use sequencing, decision making, looping, arrays and method construction.
The UML Class diagram is included with the documentation. Here is a rundown of the classes necessary for the project.
Domain Classes
Person Class
The Person class is the primary Domain class for the project. It stores the basic data for a person within the system. It utilized ne (1) other class as attributes – Date. It has the appropriate setters, getters and only one constructor.
Borrower Class
The Borrower class inherits from the Person class as a specific type of person. It contains the unique data for people who receive loans. This is the most complicated of the classes; especially, since it uses an array of class Loans. Each borrower, in this system, can have from 0 to 10 loans. When creating the Loan attribute array, you need to declare it to hold 10 elements. It has the appropriate setters, getters and one constructor. The toString method is used to output the attribute data in a formatted string for display.
toString Output Format:
📷
LoanOfficer Class
The LoanOfficer class inherits from the Person class as a specific type of person. It has the appropriate setters, getters and one constructor. The toString method is used to output the attribute data in a formatted string for display.
toString Output Format:
📷
Loan Class
The Loan class is for storing data about loans. Loans are associated with a Borrower using the Loan array in the Borrower class. Each Borrower can have up to 10 loans. Loans uses the Date and Borrower classes. All inputs to the constructor are strings. They are to be validated using the appropriate setter method.
The interest rate is always input as “nn.nn%” and must be converted to a double by the setLoanRate method. The loan rate cannot be less than 0. If so, set it to 0.
The loan amount is always input as “nnnn.nn” and must be converted to a double by the setLoanAmount method. The loan amount cannot be less than 0. If so, set it to 0.
The loan length is the time in months of the loan. It is always input as “nn” and should be converted to an integer by the method setLoanLength.
The appropriate setter must be called within the constructor when setting the instance variables to insure their validity. Do not set a loan instance variable without calling the appropriate setter for validation.
Utility Class
Date Class
The Date class is the most complicated of the utility classes. Its purpose is to store a valid date and when invalid, throw an exception. The attribute of month, day and year are integer values and should always be valid.
Date input – the date input to the constructor should be in a string formatted as mm/dd/yyyy. Any input not conforming to that format should throw an exception and store zeros (0) for all the attributes.
Month attribute – the month attribute should store the values 1 to 12. Any invalid month value should throw an exception.
Day attribute – the day attribute should store the appropriate value based on the month and leap year vs non-leap year for February. An invalid day for a month should throw an exception. For example, a day value of 31 is acceptable for January, but not for April. For February, 29 is acceptable if the year is a leap year, but not if not a leap year. Therefore, the class needs a method (isLeapYear) for determining whether the year input is a leap year or not. The method returns the Boolean TRUE if it is a leap year and FALSE if not.
Here is the algorithm for determining if a year is a leap year:
-
If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
-
If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
-
If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
-
The year is a leap year (it has 366 days, February 29.)
-
The year is not a leap year (it has 365 days, February 28.)
Year attribute – the year value is used to determine the leap year and should store values in the range of 1000 to 9999. Invalid year values should throw an exception.
Date Exceptions – The date class should throw an exception for the following reasons.
-
Time string not in the form of mm/dd/yyyy.
-
February’s day value is invalid.
-
Month value is invalid.
-
Day value for appropriate month is invalid.
-
Year value is invalid.
All methods that use the Date class should be designed to throw exceptions.
The user interface for this class is the toString method. It should be designed to return the date in the following string format – mm/dd/yyyy with leading zeros (0) for single digit values as in 01/02/2016.
Evaluation Program
Your project will be tested using the DemoLoan.java file. You may use it to test your designs, but do not modify the file except for testing dates etc.
9 public class DemoLoan
10 {
11 public static void main(String[] args)
12 {
13 try
14 {
15 //create loan officiers
16 LoanOfficer person1 = new LoanOfficer("Peter", "Washington", "01/03/2000", "02/28/2001", "L-001");
17 LoanOfficer person2 = new LoanOfficer("Mary", "Adams", "04/05/1987", "04/06/1998", "L-002");
18
19 //create borrowers
20 Borrower person3 = new Borrower("Paul", "Jefferson", "02/28/2016");
21 Borrower person4 = new Borrower("Mama", "Casselliot", "02/02/2016");
22
23 //create loans
24 new Loan("10/4/2015", "15%", "36", "1000.00", person3);
25 new Loan("08/5/2015", "10%", "24", "3000.00", person3);
26 new Loan("08/6/2015", "5%", "48", "10000.00", person4);
27 new Loan("08/7/2015", "10%", "36", "8000.00", person3);
28 new Loan("09/8/2015", "8%", "60", "12000.00", person4);
29
30
31 //output people
32 System.out.println(
33 person1.toString() + "\n" +
34 person2.toString() + "\n" +
35 person3.toString() + "\n" +
36 person4.toString() + "\n");
37
38 //output loans
39 System.out.println(
40 person3.getAllLoans() + "\n" +
41 person4.getAllLoans() + "\n");
42
43 }
44 catch (Exception e)
45 {
46 System.out.println("Error: Exception Thrown " + e.getMessage());
47 }
48 }//end of main
49 }//end of class
Posted Dec 16, 2018, 11:56 PM UTC