DPIT121 - Object Oriented Design and programming Assignment 2 (due in week 9) Start from your solution of assignment 1 or the sample solution in course webpage as the base for assignment 2. Watch...

1 answer below »
Hi this is my assignment 2 which is continued part of all labs and assignment 1 you guys did for me I'll attached all previous documents kindly do this for me and make sure you that you will submit to me on time I have request kindly give this to the expert who did previous of this chain


DPIT121 - Object Oriented Design and programming Assignment 2 (due in week 9) Start from your solution of assignment 1 or the sample 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 plans in the User class and ArrayList of users in the MobileCompany 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 MobilePlan, User, and MobileCompany classes: Inside MobilePlan: static ArrayList< mobileplan=""> shallowCopy(ArrayList< mobileplan=""> plans) static ArrayList< mobileplan=""> deepCopy(ArrayList< mobileplan=""> plans) static ArrayList< mobileplan>  shallowCopy (HashMap< integer, mobileplan =""> plans)  static ArrayList< mobileplan>  deepCopy (HashMap< integer, mobileplan =""> plans)  static HashMap< integer,mobileplan >shallowCopyHashMap(HashMap< integer, mobileplan =""> plans)  static HashMap< integer,mobileplan > deepCopyHashMap(HashMap< integer, mobileplan =""> plans)  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 deepCopyPlans() // note that these methods are not static ArrayList shallowCopyPlans() HashMap< integer,mobileplan=""> deepCopyPlansHashMap() HashMap< integer,mobileplan > shallowCopyPlansHashMap() Inside MobileCompany: ArrayList deepCopyUsers() // note that these methods are not static ArrayList shallowCopyUsers() HashMap< integer,user=""> deepCopyUsersHashMap() HashMap< integer,user > shallowCopyUsersHashMap() 4) MyDate, Plan, and User have implemented Comparable interface with proper compareTo() methods. User also has a compareTo1() method to compare users based on the total monthly payments. 5) These sort methods are implemented in User and MobileCompany classes based on lab 4: In User class : ArrayList sortPlansByDate() In MobileCompany: ArrayList sortUsers() 6) Data aggregation methods are done and tested properly based on lab 5: In User class : HashMap getTotalCountPerMobileModel () HashMap getTotalPaymentPerMobileModel () void reportPaymentMobileModel(HashMap counts,HashMap totals) In MobileCompany: HashMap getTotalPaymentPerCity() HashMap getTotalCountPerMobileModel () HashMap getTotalPaymentPerMobileModel() void reportPaymentMobileModel(HashMap counts,HashMap totals) void reportPaymentPerCity(HashMap<> totals) 7) Proper Exception Handling has been added to your code to catch InputMismatchException, PlanException, 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 MobilePlan: static hashMap load (String fileName) //binary file using serializable static boolean save (HashMap, String fileName) static HashMaploadTextFile (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 HashMaploadTextFile (String fileName)//using toDelimitedString static boolean saveTextFile (HashMap, String fileName) Inside MobileCompany: boolean load (String fileName) //load the MobileCompany including all plans/users from a binary file boolean save (String fileName) boolean loadFromTextFile (String fileName) boolean saveToTextFile (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 6 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 monthly payment. It can be an inner class inside class MobileCompany 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 sortUsersByMonthlyPayment() to the MobileCompany 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 MobilePlan constructor to check if the given username has this pattern: USRxxxxxxU (“USR” followed by 6 digits followed by “U”), 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 PlanException class for planID. You need another exception for username now. 5) Add the following method to the class MobileCompany: 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 MobileCompany to get a date as input and returns a HashMap of user full name ( the name of the user and not the plan’s username) as key and for each name all the mobile plans owned by that user and expired by that given date: HashMap<>>filterPlansByExpiryDate (MyDate expiryDate) 7) Modify your test code from lab 4 to 6 to check all the new methods including shallow and deep copy of plans, users, and mobile company, sorting plans and users by calling the methods ( both Comparable and Comparator), saving and loading the mobile 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 MobileCompany class with the minimum or no dependency to other classes i.e., you don’t create objects or directly call methods from MobilePlan 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 MobileCompany 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.addPlan (String username, String password, MobilePlan plan) double User. calcTotalPayment (String username, String password) boolean MobileCompany.addPlan (String adminUsername, String adminPassword, int userID, MobilePlan plan) double MobileCompany.calcTotalPayment (String adminUsername, String adminPassword, int userID) Note that MobileCompany has access to all users and can call getUsername() and getPassword() to be able to access User methods if admin login details are provided. UI also stores the username and password for a session and send them to the methods when required. Advanced Level (12 marks: extra 2 marks from Standard) 1- Study the Bank example from week 1 to understand that how a balance range is stored as an array and how the number of accounts per each range is reported. Add following methods to your code: User: int [] planCount ( String username, string password, int [] ranges) // gets a range array as input and returns the number of plans the user owns per range as output if user validation is successful (username and password is sent to the method for validation). Range array is the range of monthly payment for plans in all following methods. MobileCompany: int [] planCount ( String adminUsername, String adminPassword, int [] ranges) // gets a range array as input and returns the number of plans in the company per rang as output if validation is successful. MobileCompany: HashMap planCityCount(String adminUsername, String adminPassword, int [] ranges) // gets a range array as input and returns the number of plans in the company per range per city. City is the HashMap key. MobileCompany: int[] userCount (String adminUsername, String adminPassword, int [] ranges) // gets a range array as input and returns the number of users in the company per range. MobileCompany: HashMap userMobileModelCount (String adminUsername, String adminPassword, int [] ranges) // gets a range array as input and returns the number of users in the company per range per mobile model. Mobile model is the HashMap key. User: HashMap planMobileModelCount (String username, string password, int [] ranges) // gets a range array as input and returns the number of plans owned by this user per range per mobile model. Mobile model is the HashMap key. MobileCompany: HashMap planMobileModelCount (String adminUsername, String adminPassword, int [] ranges) // gets a range array as input and returns the number of plans in the company per range per mobile model. Mobile model is the HashMap key. You should call the corresponding method in User to do it for the mobile company. Check the test scenario (located in Assignment II test materials folder) to see how to test and validate these methods.
Answered 1 days AfterMay 05, 2021

Answer To: DPIT121 - Object Oriented Design and programming Assignment 2 (due in week 9) Start from your...

Rushendra answered on May 06 2021
145 Votes
Lab7/.classpath

    
        
            
        
    
    
    
Lab7/.project

     Lab7
    
    
    
    
        
             org.eclipse.jdt.core.javabuilder
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
Lab7/.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=15
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=15
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.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=15
Lab7/bin/onedrive/Address.class
Lab7/bin/onedrive/BusinessPlan.class
Lab7/bin/onedrive/DPIT121-Lab 6.docx
DPIT121 – Lab Exercise 6
Due: Week 8 lab
In lab 6, you will continue on another iteration focusing on Persistence layer of your software to Save and load your data into / from text file as well as binary file. Th
is acts as a simple database for your software. You will use a proper relational database in assignment III.
Download and study lecture codes from week 6. Also, study Lab 3 Solution from “Sample labs 4-6 and Solutions” folder which is similar to this lab.
Marking Guide: 0.5 mark for each item.
1) Study InheritanceFilingSerialization.java and InheritanceFilingSerialization2.java from week 6 to learn how to read and write parent and children classes (Inheritance) as well as classes with simple and complex aggregation/composition in the binary file by using java Serialization. Make all of your classes (except the program and UI) Serializable (i.e., to implement Serializable interface).
2- Add static methods to your MobilePlan to read and write a HashMap of plans from/to a binary file by using Serialization:
    HashMap load (String fileName)
    Boolean save (HashMap, String fileName)
3- Add static methods to User class to read and write a HashMap of users from/to a binary file by using Serialization (The same as 2)
4- Add these methods to your MobileCompany to read and write a MobileCompany object from/to a binary file by using Serialization. As you are using Serializable you only need to save and load one mobileCompany object to save and load all the users and plans. Note that these methods are NOT static.
Boolean load (String fileName) // in your test create an empty object with default constructor and then call object.load to fill the information from file to the object
    Boolean save (String fileName) // to save the object (this) into the file.
5- Study InheritanceFiling.java from week 6 lecture code to learn how to read and write parent and children objects (Inheritance) in the text file. Add toDilimatedString() method to MyDate, MobilePhone, MobilePlan, PersonalPlan, and BusinessPlan with proper object identifications.
6- Add static methods to your MobilePlan to read and write a HashMap of plans from/to a text file by using toDilimatedString():
    HashMap loadTextFile (String fileName)
    Boolean saveTextFile (HashMap, String fileName)
7- Add toDilimatedString() to User class. Then add static methods to User class to read and write a HashMap of users from/to a text file by using toDilimatedString() (The same as 6). Here for each user you can assume that number of plans is stored as a field and then a list of plans (comma separated) in each record. Check the Employer and list of projects in supplementary lab 3 part 4&5 sample codes.
8- Add toDilimatedString() to the MobileCompany ( to convert the whole company including all users and all plans to a list of comma separated records). Then add these methods to your MobileCompany to read and write a MobileCompany object from/to a text file by using toDilimatedString().
Boolean load (String fileName)
    Boolean save (String fileName)
Note that another option is to have separate files for company, list of users, and list of plans. In user file, instead of having all the plans’ information in the record only put the plan IDs and in the MobileCompany store a list of user IDs and not full users’ information. In the loading process create a hashmap of all users and a hashmap of all plans from their own files and then use addUser and addPlan methods in the company to populate all users and plans in the memory. You will do this in your assignment II. For this lab, you don’t need to do it.
9) Add test code to test all of these methods for both binary and text file. You need to submit these files in addition to your Java files. Show that after saving, clearing your hashmaps and loading them again, the data is correctly stored and loaded. Hint : Check lab 6 test ideas.java
10) Add options to load and save binary and text files to your UI.
Submit Text and Binary files with your Java files.
Lab7/bin/onedrive/MobileCompany.class
Lab7/bin/onedrive/MobilePhone$MobileType.class
Lab7/bin/onedrive/MobilePhone.class
Lab7/bin/onedrive/MobilePlan.class
Lab7/bin/onedrive/MyDate.class
Lab7/bin/onedrive/PersonalPlan.class
Lab7/bin/onedrive/Plan.class
Lab7/bin/onedrive/Tester.class
Lab7/bin/onedrive/TestMobilePlan.class
Lab7/bin/onedrive/UI.class
Lab7/bin/onedrive/UIImpl.class
Lab7/bin/onedrive/UIObjectProxy.class
Lab7/bin/onedrive/User.class
Lab7/bin/onedrive/UserNameException.class
Lab7/mobileCompany.txt
¬í��sr��onedrive.MobileCompany�����������I��flatRateL�
adminPasswordt��Ljava/lang/String;L�
adminUsernameq�~��L��nameq�~��L��userst��Ljava/util/HashMap;xp���ôt��Adminq�~��t��Mobile companyp
Lab7/plans.txt
╛М��sr��java.util.HashMap��зац�`я���F�
loadFactorI�    thresholdxp?@������w���������sr��java.lang.Integer�Б═╓В│┤8���I��valuexr��java.lang.Number├╛∙��■Ю▀���xp����sr��onedrive.PersonalPlan�����������L��cityt��Ljava/lang/String;xpt��Sydeneyx
Lab7/src/onedrive/Address.java
Lab7/src/onedrive/Address.java
package onedrive;
import java.io.Serializable;
public class Address implements Serializable,Cloneable {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private int streetNum;
    private String street;
    private String city;



    @Override
    protected Object clone() throws CloneNotSupportedException {
        // TODO Auto-generated method stub
        return super.clone();
    }
    public Address(int streetNum, String street, String city) {
        this.streetNum = streetNum;
        this.street = street;
        this.city = city;
    }
    public int getStreetNum() {
        return streetNum;
    }
    public void setStreetNum(int streetNum) {
        this.streetNum = streetNum;
    }
    public String getStreet() {
        return street;
    }
    public void setStreet(String street) {
        this.street = street;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }

    @Override
    public String toString() {
        StringBuffer addrObj = new StringBuffer();
        addrObj.append("Street No: ").append(getStreetNum()).append("\n")
        .append("Street name: ").append(getStreet()).append("\n")
        .append("City: ").append(city);

        return addrObj.toString();
    }


}
Lab7/src/onedrive/BusinessPlan.java
Lab7/src/onedrive/BusinessPlan.java
package onedrive;
import java.io.Serializable;
public class BusinessPlan extends MobilePlan implements Serializable,Cloneable{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    int numberOfEmployees;
    int ABN;
    @Override
    protected Object clone() throws CloneNotSupportedException {
        // TODO Auto-generated method stub
        return super.clone();
    }
    public BusinessPlan(String userName, int id, MobilePhone handset, int internetQuota, int capLimit,
            int numberOfEmployees, int ABN) throws UserNameException {
        super(userName, id, handset, internetQuota, capLimit);
        this.numberOfEmployees = numberOfEmployees;
        this.ABN = ABN;
    }
    @Override
    double calcPayment(int flatRate) {
        double price = 0;
        price += getHandset().getPrice()/24;
        price += getCapLimit()/10;
        price += getInternetQuota()*10;
        price += flatRate;

        if(this.numberOfEmployees > 10) {
            price += (this.numberOfEmployees-10)*50;
        }
        return price;
    }

 
    @Override
    public String toString() {
        return "BusinessPlan [numberOfEmployees=" + numberOfEmployees + ", ABN=" + ABN + "]";
    }
    @Override
    public void print() {
    super.print();
    System.out.println(numberOfEmployees + " : " + ABN + "\n");
    }
}
Lab7/src/onedrive/DPIT121-Lab 6.docx
DPIT121 – Lab Exercise 6
Due: Week 8 lab
In lab 6, you will continue on another iteration focusing on Persistence layer of your software to Save and load your data into / from text file as well as binary file. This acts as a simple database for your software. You will use a proper relational database in assignment III.
Download and study lecture codes from week 6. Also, study Lab 3 Solution from “Sample labs 4-6 and Solutions” folder which is similar to this lab.
Marking Guide: 0.5 mark for each item.
1) Study InheritanceFilingSerialization.java and InheritanceFilingSerialization2.java from week 6 to learn how to read and write parent and children classes (Inheritance) as well as classes with simple and complex aggregation/composition in the binary file by using java Serialization. Make all of your classes (except the program and UI) Serializable (i.e., to implement Serializable interface).
2- Add static methods to your MobilePlan to read and write a HashMap of plans from/to a binary file by using Serialization:
    HashMap load (String fileName)
    Boolean save (HashMap, String fileName)
3- Add static methods to User class to read and write a HashMap of users from/to a binary file by using Serialization (The same as 2)
4- Add these methods to your MobileCompany to read and write a MobileCompany object from/to a binary file by using Serialization. As you are using Serializable you only need to save and load one mobileCompany object to save and load all the users and plans. Note that these methods are NOT static.
Boolean load (String fileName) // in your test create an empty object with default constructor and then call object.load to fill the information from file to the object
    Boolean save (String fileName) // to save the object (this) into the file.
5- Study InheritanceFiling.java from week 6 lecture code to learn how to read and write parent and children objects (Inheritance) in the text file. Add toDilimatedString() method to MyDate, MobilePhone, MobilePlan, PersonalPlan, and BusinessPlan with proper object identifications.
6- Add static methods to your MobilePlan to read and write a HashMap of plans from/to a text file by using toDilimatedString():
    HashMap loadTextFile (String fileName)
    Boolean saveTextFile (HashMap, String fileName)
7- Add toDilimatedString() to User class. Then add static methods to User class to read and write a HashMap of users from/to a text file by using toDilimatedString() (The same as 6). Here for each user you can assume that number of plans is stored as a field and then a list of plans (comma separated) in each record. Check the Employer and list of projects in supplementary lab 3 part 4&5 sample codes.
8- Add toDilimatedString() to the MobileCompany ( to convert the whole company including all users and all plans to a list of comma separated records). Then add these methods to your MobileCompany to read and write a MobileCompany object from/to a text file by using toDilimatedString().
Boolean load (String fileName)
    Boolean save (String fileName)
Note that another option is to have separate files for company, list of users, and list of plans. In user file, instead of having all the plans’ information in the record only put the plan IDs and in the MobileCompany store a list of user IDs and not full users’ information. In the loading process create a hashmap of all users and a hashmap of all plans from their own files and then use addUser and addPlan methods in the company to populate all users and plans in the memory. You will do this in your assignment II. For this lab, you don’t need to do it.
9) Add test code to test all of these methods for both binary and text file. You need to submit these files in addition to your Java files. Show that after saving, clearing your hashmaps and loading them again, the data is correctly stored and loaded. Hint : Check lab 6 test ideas.java
10) Add options to load and save binary and text files to your UI.
Submit Text and Binary files with your Java files.
Lab7/src/onedrive/lab 6 test ideas.java
Lab7/src/onedrive/lab 6 test...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here