Answer To: DPIT121 - Object Oriented Design and programming Assignment 2 (due in week 9) Start from your...
Rushendra answered on May 06 2021
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. 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/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...