DPIT121 – Lab Exercise 4 Due: Week 6 lab You already submitted phase one of your project delivery as assignment I. In lab 4, you will continue on another iteration focusing on copy constructor,...

1 answer below »
These are three different labs, lab 4, 5 and 6, which need to be done separately in their own folders respectively, once you finish lab 4 you can start working on lab 5, each lab is a pre requisite of the previous lab


DPIT121 – Lab Exercise 4 Due: Week 6 lab You already submitted phase one of your project delivery as assignment I. In lab 4, you will continue on another iteration focusing on copy constructor, interface, comparable, Cloneable, shallow copy, deep copy, and sorting the list of objects. Download and study lecture codes from week 4 ( 3 recorded lectures). In particular completely understand the advanced shallow and deep copy example in depth. Also, study Lab1 Solution from “Sample labs 4-6 and Solutions” folder which is similar to this lab. 1) Add a copy constructor to your MyDate, MobilePhone, MobilePlan, PersonalPlan, BusinessPlan, User, Address, and MobileCompany 2) Implement Cloneable interface (override clone ( ) method) for MyDate, MobilePhone, MobilePlan, User, Address, and MobileCompany. Note that PersonalPlan and BusinessPlan don’t need to implement Cloneable as it is the same as their parent MobilePlan. 3) Write static methods in MobilePlan class to make shallow and deep copy of an ArrayList of plans. Use only the clone ( ). Copy constructor is not needed as it doesn’t work with inheritance and polymorphism: ArrayList< mobileplan=""> shallowCopy(ArrayList< mobileplan=""> plans) ArrayList< mobileplan=""> deepCopy(ArrayList< mobileplan=""> plans) 4) Write static methods in User class to make shallow and deep copy of an ArrayList of users (The same as 3). 5) Add a method ArrayList deepCopyPlans() to the User to create a deep copy of user’s plans. 6) Add a method ArrayList shallowCopyPlans() to the User to create a shallow copy of user’s plans. 7) Add a method ArrayList deepCopyUsers() to the MobileCompany to create a deep copy of all the users within the company. 8) Add a method ArrayList shallowCopyUsers() to the MobileCompany to create a shallow copy of all the users within the company. 9) Implement Comparable interface for MobilePlan to compare MobilePlans based on the expiry date. Note: you need to make MyDate comparable too. 10) Implement Comparable interface for User based on the city name. Note: you need to make address comparable too. 11) Add compareTo1() to the User based on the total plan monthly payments for the plans he owns. This can be replaced with the compareTo() if required. Note: assume a constant flatRate. 12) Add a method ArrayList sortPlansByDate() to the User to sort all the user’s plans based on the expiry date (using Comparable) and return it as an ArrayList. Note: You need to use Collections.sort(). 13) Add a method ArrayList sortUsers() to the MobileCompany to sort all the company’s users based on the city name (or total monthly payments if you manually change compareTo() and compareTo1() in User class and return it as an ArrayList. 14) Add this to your test code: - For a user call deepCopyPlans() and shallowCopyPlans() to make deep and shallow copies of user’s plans and store these lists in the test code. - change the user’s city to “New York” and add a new plan to his plans. - sort the user’s plans by calling sortPlansByDate(). - print the shallow and deep copy lists as well as user’s plans and see how these three lists are compared. - For a mobileCompany call deepCopyUsers() and shallowCopUsers() to make deep and shallow copies of company’s users and store these lists in the test code. - add a new user to the company. - sort the company’s users by calling sortUsers(). - print the shallow and deep copy lists as well as company’s users and see how these three lists are compared. - make a clone of the mobileCompany in your test code and test to show it is a deep copy. 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 plans in the User class and users in the MobileCompany and replace it with HashMaps. The HashMap key is the planID and userID and the value is the corresponding plan 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: - Comment the old code and modify the addPlan, findPlan, addUser, and findUser for Hashmap instead of ArrayList. - Keep all the static methods: print, filter, calcTotalPayment, and mobilePriceRiseAll for ArrayList inside the MobilePlan class but add new methods with the same names but for a HashMap of plans. - 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 MobilePlan 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 inside the MobilePlan but add these methods to MobilePlan: ArrayList< mobileplan=""> shallowCopy (HashMap< integer,="" mobileplan=""> plans) ArrayList< mobileplan=""> deepCopy (HashMap< integer,="" mobileplan=""> plans) HashMap< integer,="" mobileplan=""> shallowCopyHashMap (HashMap< integer,="" mobileplan=""> plans) HashMap< integer,="" mobileplan=""> deepCopyHashMap (HashMap< integer,="" mobileplan=""> plans) - Comment the old code for shallow copy and deep copy methods inside the User and MobileCompany and modify them to work with HashMaps. Note that these methods still should return an ArrayList of plans and users. Add new versions of these methods to return HashMaps of plans and users. - The sort methods inside the User and MobileCompnay still should return an ArrayList as HashMap is not sortable. Comment the old code and modify it to make a shallow copy of plan 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: HashMap getTotalCountPerMobileModel () // which aggregates the number of plans the user owns for any given mobile model as and returns the hashmap. HashMap getTotalPaymentPerMobileModel () // which aggregates the total monthly payments of plans the user owns for any given mobile model as a 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: Mobile Model Total Monthly Payment Average Monthly Payment Iphone X $1,050.00 $105.00 Samsung Galaxy 10 $425.00 $85.00 (Assume this user has ten plans with the Mobile Model of “Iphone X” and five with Samsung Galaxy 10) 3- For data aggregation reports add following methods to the class MobileCompany: HashMap getTotalPaymentPerCity() // which aggregates the total monthly payments for users from any given city within the company as e.g., we have three users from Wollongong, two from Sydney, etc HashMap getTotalCountPerMobileModel () // returns a list of pairs of (Mobile Model, Count) as a HashMap across all the users within the company (by calling the corresponding method inside User) HashMap getTotalPaymentPerMobileModel () // returns a list of pairs of (Mobile Model, Total Monthly 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 MobileCompany to generate these reports from the aggregated hashmaps: City Name Total Monthly Payments Wollongong $10,500.00 Sydney $45,980.00 Assuming that there are 110 users with the city=”Wollongong” and the total of monthly payments for all of their plans is $10,500 And the same as 2 but across all users: Mobile Model Total Monthly Payment Average Monthly Payment Iphone X $10,500.00 $105.00 Samsung Galaxy 10 $15,300.00 $51.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 mobile 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). 5) Let’s assume that Plan ID should be 6 digits starting with 3: - Add a new Exception Class PlanException with one field: int ID. - In the Plan constructor if the given ID does not follow the required pattern: - Generate a random ID with the given pattern 3xxxxxx - Throw a PlanException by passing the generated ID as an argument to PlanException constructor. - The toString() method in PlanException creates an error message “ The Plan ID was not valid and a new ID (the generated ID) is generated by admin and assigned for the Plan”. 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 Personal or Business Plan with the user information but the generated ID and add it to the user plans. 6) Modify your test code for the modified code in this lab in particular calling all the data aggregation methods. 7) Add following options to your basic UI: - Option 9 to report Mobile Model, Total Monthly Payment, and Average Monthly Payment for a given user - Option 10 to report City Name, Total
Answered Same DaySep 05, 2021

Answer To: DPIT121 – Lab Exercise 4 Due: Week 6 lab You already submitted phase one of your project delivery as...

Valupadasu answered on Sep 10 2021
147 Votes
Lab4/.classpath

    
    
    
Lab4/.project

     Lab4
    
    
    
    
        
             org.eclipse.jdt.core.javabuilder
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
Lab4/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Lab4/bin/main01/Address.class
package main01;
public synchronized class Address implements Comparable {
private int streetNum;
private String street
;
private String suburb;
private String city;
public void Address(int, String, String, String);
public void Address(Address);
public Address clone() throws CloneNotSupportedException;
public int getStreetNum();
public String getStreet();
public String getSuburb();
public String getCity();
public void setStreetNum(int);
public void setStreet(String);
public void setSuburb(String);
public void setCity(String);
public String toString();
public int compareTo(Address);
}
Lab4/bin/main01/BusinessPlan.class
package main01;
public synchronized class BusinessPlan extends MobilePlan implements Cloneable {
protected int numberOfEmployees;
protected int ABN;
public void BusinessPlan(String, int, MobilePhone, int, int, MyDate, int, int);
public void BusinessPlan(BusinessPlan);
public BusinessPlan clone() throws CloneNotSupportedException;
public int getNumberOfEmployees();
public int getABN();
public void setNumberOfEmployees(int);
public void setABN(int);
public void print();
public String toString();
public double calcPayment(int);
}
Lab4/bin/main01/Main01.class
package main01;
public synchronized class Main01 {
public void Main01();
public static void main(String[]);
public static void addPlan(User, MobilePlan);
}
Lab4/bin/main01/MobileCompany.class
package main01;
public synchronized class MobileCompany implements Cloneable {
private String name;
private java.util.ArrayList users;
private String adminUsername;
private String adminPassword;
private int flatRate;
public void MobileCompany(String, java.util.ArrayList, String, String, int);
public void MobileCompany(MobileCompany);
public java.util.ArrayList deepCopyUsers();
public java.util.ArrayList shallowCopyUsers();
public MobileCompany clone() throws CloneNotSupportedException;
public String getName();
public java.util.ArrayList getUsers();
public String getAdminUsername();
public String getAdminPassword();
public int getFlatRate();
public void setName(String);
public void setUsers(java.util.ArrayList);
public void setAdminUsername(String);
public void setAdminPassword(String);
public void setFlatRate(int);
public boolean validateAdmin(String, String);
public boolean addUser(User);
public Boolean addUser(String, int, Address);
public User findUser(int);
public boolean addPlan(int, MobilePlan);
public MobilePlan findPlan(int, int);
public void printPlans(int);
public void print();
public String toString();
public boolean createPersonalPlan(int, String, int, MobilePhone, int, int, MyDate, String);
public boolean createBusinessPlan(int, String, int, MobilePhone, int, int, MyDate, int, int);
public double calcTotalPayments(int);
public double calcTotalPayments();
public boolean mobilePriceRise(int, double);
public void mobilePriceRise(double);
public java.util.ArrayList allPlans();
public java.util.ArrayList filterByMobileModel(int, String);
public java.util.ArrayList filterByExpiryDate(int, MyDate);
public java.util.ArrayList filterByMobileModel(String);
public java.util.ArrayList filterByExpiryDate(MyDate);
public java.util.ArrayList sortUsers();
}
Lab4/bin/main01/MobilePhone.class
package main01;
public synchronized class MobilePhone implements Cloneable {
private String model;
private mobileType type;
private int memorySize;
private double price;
public void MobilePhone(String, mobileType, int, double);
public void MobilePhone(MobilePhone);
public MobilePhone clone() throws CloneNotSupportedException;
public String getModel();
public mobileType getType();
public int getMemorySize();
public double getPrice();
public void setModel(String);
public void setType(mobileType);
public void setMemorySize(int);
public void setPrice(double);
public void priceRise(double);
public void print();
public String toString();
}
Lab4/bin/main01/MobilePlan.class
package main01;
public abstract synchronized class MobilePlan implements Comparable {
protected String userName;
protected int id;
protected MobilePhone handset;
protected int internetQuota;
protected int capLimit;
protected MyDate expiryDate;
public void MobilePlan(String, int, MobilePhone, int, int, MyDate);
public void MobilePlan(MobilePlan);
public static java.util.ArrayList filterByExpiryDate(java.util.ArrayList, MyDate);
public MobilePlan clone() throws CloneNotSupportedException;
public static java.util.ArrayList shallowCopy(java.util.ArrayList);
public static java.util.ArrayList deepCopy(java.util.ArrayList);
public String getUserName();
public int getId();
public MobilePhone getHandset();
public int getInternetQuota();
public int getCapLimit();
public MyDate getExpiryDate();
public void setHandSet(MobilePhone);
public void setInternetQuota(int);
public void setCapLimit(int);
public void setExpiryDate(MyDate);
public void setMobileModel(String);
public void setUserName(String);
public void print();
public String toString();
public abstract double calcPayment(int);
public static void printPlans(java.util.ArrayList);
public static double calcTotalPayments(java.util.ArrayList, int);
public void mobilePriceRise(double);
public static void mobilePriceRiseAll(java.util.ArrayList, double);
public static java.util.ArrayList filterByMobileModel(java.util.ArrayList, String);
public int compareTo(MobilePlan);
}
Lab4/bin/main01/mobileType.class
package main01;
final synchronized enum mobileType {
public static final mobileType ANDRIOD;
public static final mobileType IOS;
public static final mobileType WINDOWS;
static void ();
private void mobileType(String, int);
public static mobileType[] values();
public static mobileType valueOf(String);
}
Lab4/bin/main01/MyDate.class
package main01;
public synchronized class MyDate implements Cloneable, Comparable {
protected int year;
protected int month;
protected int day;
public void MyDate(int, int, int);
public void MyDate(MyDate);
public MyDate clone() throws CloneNotSupportedException;
public Boolean isExpired(MyDate);
public int getYear();
public int getMonth();
public int getDay();
public void setYear(int);
public void setMonth(int);
public void setDay(int);
public String toString();
public int compareTo(MyDate);
}
Lab4/bin/main01/PersonalPlan.class
package main01;
public synchronized class PersonalPlan extends MobilePlan {
protected String city;
public void PersonalPlan(String, int, MobilePhone, int, int, MyDate, String);
public void PersonalPlan(PersonalPlan);
public String getCity();
public void setCity(String);
public void print();
public String toString();
public double calcPayment(int);
}
Lab4/bin/main01/User.class
package main01;
public synchronized class User implements Comparable {
private String name;
private int userID;
private Address address;
private java.util.ArrayList plans;
public void User(String, int, Address);
public void User(User);
public User clone() throws CloneNotSupportedException;
public java.util.ArrayList deepCopyPlans();
public java.util.ArrayList shallowCopyPlans();
public static java.util.ArrayList shallowCopy(java.util.ArrayList);
public static java.util.ArrayList deepCopy(java.util.ArrayList);
public boolean createPersonalPlan(String, int, MobilePhone, int, int, MyDate, String);
boolean createBusinessPlan(String, int, MobilePhone, int, int, MyDate, int, int);
public java.util.ArrayList filterByExpiryDate(MyDate);
public String getName();
public int getUserID();
public Address getAddress();
public java.util.ArrayList getPlans();
public void setName(String);
public void setAddress(Address);
public void setCity(String);
public MobilePlan findPlan(int);
public boolean addPlan(MobilePlan);
public boolean addPlan1(java.util.ArrayList, MobilePlan);
public void print();
public String toString();
public void printPlans(int);
public double calcTotalPayments(int);
public void mobilePriceRiseAll(double);
public java.util.ArrayList filterByMobileModel(String);
public int compareTo(User);
public int compareTo1(User);
public java.util.ArrayList...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here