DPIT121 – Lab Exercise 5Due: Week 7 labIn lab 5, you will continue on another iteration focusing on HashMap as a Data Structure and for Data Aggregation, and Exception Handling.Download and...

I've attached the files required as well as my prior code of lab 4. I need lab 5, 6 and Assignment 2 completed please. Lab5 and 6 are overdue. Thanks


DPIT121 – Lab Exercise 5 Due: Week 7 lab In lab 5, you will continue on another iteration focusing on HashMap as a Data Structure and for Data Aggregation, and Exception Handling. Download and study lecture codes from week 5. Also, study Lab 2 Solution from “Sample labs 4-6 and Solutions” folder which is similar to this lab. 1) Comment the ArrayList of policies in the User class and users in the InsuranceCompany and replace it with HashMaps. The HashMap key is the policyID and userID and the value is the corresponding policy and user, respectively. Don’t remove any codes and methods but comment the old code and modify your code/methods to be compatible with HashMaps as below: (0.5 marks) - Comment the old code and modify the addPolicy, findPolicy, addUser, and findUser for Hashmap instead of ArrayList. - Keep all the static methods: print, filter, calcTotalPayment, and carPriceRiseAll for ArrayList inside the InsurancePolicy class but add new methods with the same names but for a HashMap of policies. - Comment the old code for print, filter, calcTotalPayment, and priceRiseAll for ArrayList inside the User class and modify them for the new static methods inside InsurancePolicy working with HashMap. You also need to modify toString(), copy constructor, and clone() methods. - Comment the old code for any methods inside the InsuranceCompany working with ArrayList and modify it for the HashMap. - keep the old static shallow and deep copy methods of ArrayList< insurancepolicy=""> inside the InsurancePolicy but add these methods to InsurancePolicy: ArrayList< insurancepolicy>  shallowCopy(HashMap< integer, insurancepolicy=""> policies)  ArrayList< insurancepolicy>  deepCopy (HashMap< integer, insurancepolicy=""> policies)  HashMap< integer, insurancepolicy=""> shallowCopyHashMap (HashMap< integer, insurancepolicy=""> policies)  HashMap< integer, insurancepolicy =""> deepCopyHashMap (HashMap< integer, insurancepolicy =""> policies)  - Comment the old code for shallow copy and deep copy methods inside the User and InsuranceCompany and modify them to work with HashMaps. Note that these methods still should return an ArrayList of policies and users. Add new versions of these methods to return HashMaps of policies and users. - The sort methods inside the User and InsuranceCompnay still should return an ArrayList as HashMap is not sortable. Comment the old code and modify it to make a shallow copy of Policy and User HashMaps to ArrayLists first, and then sort the ArrayList and return it. 2) For data aggregation reports by using HashMap add following methods to the class User: (0.5 marks) HashMap getTotalCountPerCarModel () // which aggregates the number of policies the user owns for any given car model as and returns the hashmap. HashMap getTotalPremiumPerCarModel () // which aggregates the total premium payments of policies the user owns for any given car model as a list of pairs of and returns the HashMap - Add proper report methods to the class User to generate this report from the aggregated hashmaps: Car ModelTotal Premium PaymentAverage Premium Payment Toyota Camry 2018 $10,050.00 $1,050.00 Nissan Dualis 2017 $4,025.00 $850.00 (Assume this user has ten policies with the Car Model of “Toyota Camry 2018” and five with Nissan Dualis 2017) 3- For data aggregation reports add following methods to the class InsuranceCompany: (1.25 marks) HashMap getTotalPremiumPerCity() // which aggregates the total premium payments for users from any given city within the company as e.g., we have three users from Wollongong, two from Sydney, etc HashMap getTotalCountPerCarModel () // returns a list of pairs of (Car Model, Count) as a HashMap across all the users within the company (by calling the corresponding method inside User) HashMap getTotalPremiumPerCarModel () // returns a list of pairs of (Car Model, Total Premium Payments) as a HashMap across all the users within the company (by calling the corresponding method inside User) - Add proper report methods to the class InsuranceCompany to generate these reports from the aggregated hashmaps: City Name Total Premium Payments Wollongong $100,500.00 Sydney $450,980.00 Assuming that there are 110 users with the city=”Wollongong” and the total premium payments for all of their policies is $100,500 And the same as 2 but across all users: Car ModelTotal Premium PaymentAverage Premium Payment Toyota Camry 2018 $100,050.00 $1,150.00 Nissan Dualis 2017 $40,025.00 $750.00 4) Add try catch to any section of the code that the program uses Scanner to read from the console and catch the InputMismatchException to catch any wrong input (e.g., String entry for a number) and prompt user. Keep asking user to enter the proper data. Your program should not stop/crash but to continue normally after the catch. In particular modify your UI option 2, 3, 4, and 8. If admin enters a wrong data (such as a string for street number or car price) prompt the admin to enter the correct data type and keep asking for the correct data without crashing (By using a while loop and a Boolean success flag the same as lecture code). (0.5 marks) 5) Let’s assume that Policy ID should be 6 digits starting with 3: (0.5 marks) - Add a new Exception Class PolicyException with one field: int ID. - In the Policy constructor if the given ID does not follow the required pattern: - Generate a random ID with the given pattern 3xxxxxx - Throw a PolicyException by passing the generated ID as an argument to PolicyException constructor. - The toString() method in PolicyException creates an error message “ The Policy ID was not valid and a new ID (the generated ID) is generated by admin and assigned for the Policy”. In your UI option 3 and 4 catch this exception and print it. Again your program should continue normally after catching this exception. You need to create the ThirdParty or Comprehensive Policy with the user information but the generated ID and add it to the user policies. 6) Modify your test code for the modified code in this lab in particular calling all the data aggregation methods. (1.0 marks) 7) Add following options to your basic UI: (0.75 marks) - Option 9 to report Car Model, Total Premium Payment, and Average Premium Payment for a given user - Option 10 to report City Name, Total Premium Payments across all users - Option 11 to report Car Model, Total Premium Payment, and Average Premium Payment across all users DPIT121 - Object Oriented Design and programming Assignment 2 (due in week 9) Start from your lab 6 solution or modify the sample assignment 1 solution in course webpage as the base for assignment 2. Watch video lecture 6-1 for hints This assignment has three levels: advanced (max mark is 12 out of 12), standard (max mark is 10 out of 12), or core (maximum 8 out of 12). Core Level: maximum 8% if completed in week 9 Standard Level: maximum 10% if completed in week 9 Advanced Level: maximum 12% if completed in week 9 Core Level Perquisite Requirements from Lab 4-6: (4 marks) Double check that all the requirements from lab 4, 5, and 6 are satisfied. In particular if you missed any of these requirements you can do it now: 1- All classes have copy constructor and have implemented Cloneable with proper clone() methods. 2) ArrayList of policies in the User class and ArrayList of users in the InsuranceCompany are replaced with HashMaps and all methods are modified to work with HashMap as lab 5 specifications required. 3- All 20 methods for shallow and deep copy of ArrayLists and HashMaps are done in InsurancePolicy, User, and InsuranceCompany classes: Inside InsurancePolicy: static ArrayList< insurancepolicy=""> shallowCopy(ArrayList< insurancepolicy=""> policies) static ArrayList< insurancepolicy=""> deepCopy(ArrayList< insurancepolicy=""> policies) static ArrayList< insurancepolicy>  shallowCopy (HashMap< integer, insurancepolicy =""> policies)  static ArrayList< insurancepolicy>  deepCopy (HashMap< integer, insurancepolicy =""> policies)  static HashMap< integer, insurancepolicy =""> shallowCopyHashMap (HashMap< integer, insurancepolicy =""> policies)  static HashMap< integer,insurancepolicy > deepCopyHashMap(HashMap< integer, insurancepolicy =""> policies)  Inside User: static ArrayList< user=""> shallowCopy(ArrayList< user=""> users) static ArrayList< user=""> deepCopy(ArrayList < user=""> users) static ArrayList< user>  shallowCopy (HashMap < integer, user =""> users)  static ArrayList< user>  deepCopy (HashMap < integer, user =""> users)  static HashMap< integer,user > shallowCopyHashMap(HashMap < integer, user =""> users)  static HashMap< integer,user > deepCopyHashMap(HashMap < integer, user =""> users) ArrayList deepCopyPolicies() // note that these methods are not static ArrayList shallowCopyPolicies() HashMap< integer,insurancepolicy=""> deepCopyPoliciesHashMap() HashMap< integer,insurancepolicy > shallowCopyPoliciesHashMap() Inside InsuranceCompany: ArrayList deepCopyUsers() // note that these methods are not static ArrayList shallowCopyUsers() HashMap < integer,user=""> deepCopyUsersHashMap() HashMap < integer,user > shallowCopyUsersHashMap() 4) MyDate, InsurancePolicy, and User have implemented Comparable interface with proper compareTo() methods. User also has a compareTo1() method to compare users based on the total premium payments. 5) These sort methods are implemented in User and InsuranceCompany classes based on lab 4: In User class : ArrayList sortPoliciesByDate() In InsuranceCompany: ArrayList sortUsers() 6) Data aggregation methods are done and tested properly based on lab 5: In User class : HashMap getTotalCountPerCarModel () HashMap getTotalPremiumPerCarModel () void reportPremiumCarModel (HashMap counts, HashMap totals) In InsuranceCompany: HashMap getTotalPremiumPerCity() HashMap getTotalCountPerCarModel () HashMap getTotalPremiumPerCarModel() void reportPremiumCarModel(HashMap counts,HashMap totals) void reportPremiumPerCity(HashMap<> totals) 7) Proper Exception Handling has been added to your code to catch InputMismatchException, PolicyException, IOException, etc. The program should not be crashed if any of these exceptions occur. 8) All of the classes has implemented Serializable interface and all of them have proper toDelimitedString() method. Proper methods to save and load data in/from both binary files and text files are implemented as below: Inside InsurancePolicy: static hashMap load (String fileName) //binary file using serializable static boolean save (HashMap, String fileName) static HashMap loadTextFile (String fileName)//using toDelimitedString static boolean saveTextFile (HashMap, String fileName) Inside User: static hashMap load (String fileName) //binary file using serializable static boolean save (HashMap, String fileName) static HashMap loadTextFile (String fileName)//using toDelimitedString static boolean saveTextFile (HashMap, String fileName) Inside InsuranceCompany: boolean load (String fileName) //load the InsuranceCompany including all policies/users from a binary file boolean save (String fileName) boolean loadTextFile (String fileName) boolean saveTextFile (String fileName) *Test your filing with the code in filing_test.java located in “assignment II test materials” folder by adding it to your test code. You need to submit six data files (3 binary and 3 text files) with your submission. New Requirements (4 marks) (0.5 for each item) 1) Comment compareTo1() method in User class and add a proper Comparator class to compare User objects based on the total premium payments. It can be an inner class inside class InsuranceCompany which already has flatRate to calculate the total payment. Find resources for Comparator class and how to use it in Collections.sort() in Internet and study them. 2) Add a method ArrayList sortUsersByPremium() to the InsuranceCompany to sort all the users by using the new Comparator. 3) ID generation for the User to be automatic by using a static count and increment it. 4) Use regular expression inside InsurancePolicy constructor to check if the given policyHolderName has this pattern: First name starting with capital letter and minimum 2 alphabets following by space and last name ( again starting with capital letter and minimum 2 alphabets), if not throw a user defined exception. Hint: Use java.util.regex package. You may find a tutorial here: https://www.javatpoint.com/java-regex. Note that you also has a PolicyException class for policyID. You need another exception for policyHolderName now. 5) Add the following method to the class InsuranceCompany: HashMap> getUsersPerCity() // returns a hashmap with the city name as key and a list of all the users from that city as the value. 6) Add a method to InsuranceCompany to get a date as input and returns a HashMap of user full name (The name of the user and not the policy’s policyHolderName) as the key and for each name all the policies owned by that user and expired by that given date: HashMap <>> filterPoliciesByExpiryDate (MyDate expiryDate) 7) Modify your test code from lab 4 to 6 to check all the new methods including shallow and deep copy of policies, users, and insurance company, sorting policies and users by calling the methods ( both Comparable and Comparator), saving and loading the insurance company to/from a binary file, and text file, data aggregation methods, etc. 8) Modify your UI to include options for new functionalities of your software. You should have additional options for deep copy, shallow copy, sorting, data aggregations, saving/loading, etc Standard Level (10 marks: extra 2 marks from Core) 1- Finish all the requirements for Core first. You need to have the test code to demonstrate everything is working before showing the demo of your UI. 2- You need to use proxy design pattern in your UI which means your class UI only has access to one object from InsuranceCompany class with the minimum or no dependency to other classes i.e., you don’t create objects or directly call methods from InsurancePolicy and User in your UI. Use Exception handling to handle any errors resulting from the user inputs. All the methods with boolean return value should be checked in the UI with user friendly promoting. 3- Add password to User class if you have not done it in assignment I. Add validation methods e.g., boolean userVaildate (String username, String password) if you haven’t done this in assignment I. 4- To be sure your design maintains the high level of security; all the methods inside InsuranceCompany and User should apply validation/authentication prior to do the given task. Hence you send the username and password as parameters to all methods for validation which returns false if validation is not successful e.g.: boolean User
Dec 16, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here