Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

DPIT121 Spring 2021 Final Exam Answer Sheet //Write your full name and student ID here //Don't delete anything from the template not even the comments and the questions Just add your code to make...

1 answer below »
DPIT121 Spring 2021 Final Exam Answer Sheet
Write your full name and student ID here
Don't delete anything from the template not even the comments and the questions Just add your code
to make the template complete
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.A
ayList;
import java.util.Collections;
import java.util.HashMap;
Complete the Java code to define the class MobilePhone and class MyDate as well as enum Type.

enum Type {Android, IOS, Windows};
1- Complete the Code below XXXXXXXXXXmarks)
class MobilePhone implements …………………………………………………………………………
{
private String model;
private MobileType type;
private double price;
public MobilePhone(String model,MobileType type, double price)
{
XXXXXXXXXXthis.model=model;
XXXXXXXXXXthis.type=type;
XXXXXXXXXXthis.price=price;
}
@Ove
ide
public String toString()
{
XXXXXXXXXXreturn "Model: "+model+" Type: "+type+" Price: "+price;
}
public String toDelimatedString()
{
XXXXXXXXXXreturn model+","+type+","+price;
}
public MobilePhone clone() throws CloneNotSupportedException
{

2- Complete the Code XXXXXXXXXXmarks)
}
public double getPrice()
{
XXXXXXXXXXreturn price;
}
public String getModel()
{

3- Complete the Code XXXXXXXXXXmarks)
}
public void setPrice(double price)
{

4- Complete the Code XXXXXXXXXXmarks)
}
public int compareTo(MobilePhone other)
{

5- Complete the Code to compare based on the model XXXXXXXXXXmarks)
}
public void priceRise(double rate)
{
XXXXXXXXXXprice*=(1+rate);
}
}
class MyDate implements Cloneable
{
private int year;
private int month;
private int day;
public MyDate(int y,int m,int d)
{
XXXXXXXXXXyear=y;
XXXXXXXXXXmonth=m;
XXXXXXXXXXday=d;
}
@Ove
ide
public String toString()
{

6- Complete the Code XXXXXXXXXXmarks)
}
public String toDelimatedString()
{

7- Complete the Code XXXXXXXXXXmarks)
}
public MyDate clone() throws CloneNotSupportedException
{

8- Complete the Code XXXXXXXXXXmarks)
}
}

Write an interface named PlanMonthlyPayment which has a method called calcPayment to calculate
the monthly payment.
interface PlanMonthlyPayment
{

9- Complete the Code. (0.5 marks)
}
Write an abstract base class Plan for the above scenario. This class supports the common features of
all children.
10- Complete the Code below. (0.5 marks)
abstract class Plan implements ……………………………………………………………………..…
{
protected int id;
protected String name;
protected MobilePhone handset;
protected MyDate dateOfExpiry;
protected int capLimit;
public Plan ( int id,String name,MobilePhone handset, MyDate date, int capLimit)
{

11- Complete the Code. (0.5 marks)
}
public String toString()
{

12- Complete the Code. (0.5 marks)
}
abstract public double calcPayment(double flatRate);

Implement the Comparable Interface based on mobile phone model.

13- Complete the Code for Comparable. (1.5 marks)
Implement the Cloneable Interface
14- Complete the Code to implement clone(). (2 marks)

Write two static methods inside Plan class to make shallow and a deep copy of a list of plans.
public static A
ayList shallowCopy(A
ayList plans)
{

15- Complete the Code. (1 mark)
}
public static A
ayList deepCopy(A
ayList plans) throws CloneNotSupportedException
{

16- Complete the Code. (1 mark)
}

Add toDelimitedString() to be used to save the objects in a text file. Check the hint for question 24
to understand the format.
public String toDelimatedString()
{

17- Complete the Code. (0.5 marks)

}

Write a static method inside the Plan to print a list of plans.

public static void printPlans(A
ayList plans)
{

18- Complete the Code. (1 mark)
}

Write a static method inside the Plan calculate the total monthly payments for a list of plans

public static int calcTotalPayments(A
ayList plans,double rate)
{

19- Complete the Code. (1 mark)

}

Write a static method inside the Plan to get a list of plans and a String mobileModel as input and
filter the input list and return the new filtered list.
public static A
ayList filterPlans(A
ayList plans,String model)
{

20- Complete the Code. (2 marks)
}
public String getModel()
{
return handSet.getModel();
}
Write a static method inside the Plan to get a list of plans and a double rate as input and for each
plan in the list, multiply the handset price of the plan in the given rate and create a deep copy of the
modified plans and returns the new list. Note: don’t change/modify the original list.
public static A
ayList priceRiseAll(A
ayList plans,double rate) throws CloneNotSupportedException
{

21- Complete the Code. (2 marks)
}
}
Write two su
child classes for the scenario
22- Complete the Code below XXXXXXXXXXmarks)
class PersonalPlan ………………………………………………………………………………
{
protected String city;
public PersonalPlan( int id,String name,MobilePhone handset, MyDate date,String city)
{

23- Complete the Code. (0.5 marks)
}
Implement the PlanMonthlyPayment interface for this class and ove
ide the calcPayment()
method based on the description
@Ove
ide

24- Complete the Code. (0.5 marks)
public String toString()
{

25- Complete the Code XXXXXXXXXXmarks)
}
@Ove
ide
public String toDelimatedString()
{

26- Complete the Code. (0.5 marks)
}
}
27- Complete the Code below XXXXXXXXXXmarks)
class BusinessPlan ………………………………………………………………………………
{
protected int numberOfEmployees;
protected int ABN;
public BusinessPlan(int id,String name,MobilePhone handset, MyDate date,int numberOfEmployees,int ABN)
{

28- Complete the Code. (0.5 marks)
}
Implement the PlanMonthlyPayment interface for this class and ove
ide the calcPayment()
method based on the description
@Ove
ide
29- Complete the Code. (0.5 marks)
public String toString()
{

30- Complete the Code XXXXXXXXXXmarks)
}
@Ove
ide
public String toDelimatedString()
{

31- Complete the Code. (0.5 marks)
}
}
class MobileCompany
{
private static final double flatRate=75;
public static void main(String[] args) throws CloneNotSupportedException, IOException
{
Write a test code that creates a mixture of PersonalPlan, and BusinessPlan objects, then places
them in a single list of plans, calculates their total monthly payments and finally prints the list on
the console by calling the methods inside the Plan. Note that the flatRate should be stored as a
constant in your test Class and then is sent it to the methods as a parameter.
32- Complete the Code as above. (3 marks)
Add test code to make a shallow and deep copy of the list and then sort the original list.
33- Complete the Code as above. (1 mark)

Write a test code to call the filter by mobile model method
34- Complete the Code as above. (1 mark)
Write a test code to call the mobile price modification method and print the modified list.
35- Complete the Code as above. (1 mark)

Add a test code to call data aggregation methods for the list of plans. See Questions 19-21 for
details:
Iphone X Plus $9,500
Samsung Galaxy 10 $570
36- Complete the Code as above. (1 mark)

Write a code by using Lambda and Stream to search for the customer name in the list of plans
and display the information for all the plans for the given customer (Q22)
37- Complete the Code as above. (1 mark)

Write a code by using Lambda and Stream to search for the customer name in the list of plans
and display the total monthly payments for all the plans for the given customer name. (Q23)
38- Complete the Code as above. (2 marks)
Write the test code to call load and save methods and catch the exceptions by using proper try
and catch.
39- Complete the Code as above. (1 mark)

}
Write a method to generate a “Data aggregation Report” of a list of plans to calculate the total
monthly payments for each given handset model across all plans as “Mobile Phone Model”
“Total Monthly Payment” by using HashMap. The output of the method is a
HashMap (Q19)
public static HashMap aggregate( A
ayList plans)
{

40- Complete the Code. (3 marks)
}

Write another method to print this HashMap. (Q20)
public static void report(HashMap report )
{

41- Complete the Code. (1 mark)

}
Write a method to get a filename and an A
ayList as input and writes all the plans from
the list into the file. (Q25)
public static void save(A
ayList plans,String fileName) throws IOException
{

42- Complete the Code. (2 marks)
}
Write a method that gets a fileName as an input parameter and then reads the text file and
converts the data in the file to the list of plans and returns the list (The file contains both
PersonalPlan and BusinessPlan records). (Q24)
public static A
ayList load( String fileName) throws IOException
{

43- Complete the Code. (3 marks)
}
}
Answered Same Day Jan 22, 2023

Solution

Vikas answered on Jan 23 2023
52 Votes
DPIT121 Spring 2021 Final Exam Answer Sheet
Write your full name and student ID here
Don't delete anything from the template not even the comments and the questions Just add your code to make the template complete
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.A
ayList; import java.util.Collections; import java.util.HashMap;
Complete the Java code to define the class MobilePhone and class MyDate as well as enum Type.
enum Type {Android, IOS, Windows};
1- Complete the Code below. (0.25 marks)
class MobilePhone implements Cloneable
{
private String model; private MobileType type; private double price;
public MobilePhone(String model,MobileType type, double price)
{
this.model=model; this.type=type; this.price=price;
}
@Ove
ide
public String toString()
{
eturn "Model: "+model+" Type: "+type+" Price: "+price;
}
public String toDelimatedString()
{
eturn model+","+type+","+price;
}
public MobilePhone clone() throws CloneNotSupportedException
{
2- Complete the Code. (0.25 marks)
    return (MobilePhone) super.clone();
}
public double getPrice()
{
eturn price;
}
public String getModel()
{
3- Complete the Code. (0.25 marks)
    return model;
}
public void setPrice(double price)
{
4- Complete the Code. (0.25 marks)
    this.price = price;
}
public int compareTo(MobilePhone other)
{
5- Complete the Code to compare based on the model. (0.25 marks)
    return this.model.compareTo(other.model);
}
public void priceRise(double rate)
{
price*=(1+rate);
}
}
class MyDate implements Cloneable
{
private int year; private int month; private int day;
public MyDate(int y,int m,int d)
{
year=y; month=m; day=d;
}
@Ove
ide
public String toString()
{
6- Complete the Code. (0.25 marks)
    return year+"-"+month+"-"+day;
}
public String toDelimatedString()
{
7- Complete the Code. (0.25 marks)
}
public MyDate clone() throws CloneNotSupportedException
{
8- Complete the Code. (0.25 marks)
    return year+","+month+","+day;
}
}
Write an interface named PlanMonthlyPayment which has a method called calcPayment to calculate the monthly payment.
interface PlanMonthlyPayment
{
9- Complete the Code. (0.5 marks)
    double calcPayment(double flatRate);
}
Write an abstract base class Plan for the above scenario. This class supports the common features of all children.
10- Complete the Code below. (0.5 marks)
abstract class Plan implements Cloneable, PlanMonthlyPayment, Comparable{
protected int id; protected String name;
protected MobilePhone handset; protected MyDate dateOfExpiry;
protected int capLimit;
public Plan ( int id,String name,MobilePhone handset, MyDate date, int capLimit)
{
11- Complete the Code. (0.5 marks)
    this.id = id; this.name = name;
this.handset = handset;
this.dateOfExpiry = date;
this.capLimit = capLimit;
}
public String toString()
{
12- Complete the Code. (0.5 marks)
return "ID: "+id+" Name: "+name+" Handset: "+handset+" Expiry Date: "+dateOfExpiry+" Cap Limit: "+capLimit;
}
abstract public double calcPayment(double flatRate);
Implement the Comparable Interface based on mobile phone model.
13- Complete the Code for Comparable. (1.5 marks)
public int compareTo(Plan other) {
eturn this.handset.compareTo(other.handset);
}
Implement the Cloneable Interface
14- Complete the Code to implement clone(). (2 marks)
public Plan clone() throws CloneNotSupportedException {
Plan plan = (Plan) super.clone();
plan.handset = this.handset.clone();
plan.dateOfExpiry = this.dateOfExpiry.clone();
eturn plan;
Write two static methods inside Plan class to make shallow and a deep copy of a list of plans. public static A
ayList shallowCopy(A
ayList plans)
{
15- Complete the Code. (1 mark)
    return new A
ayList
(plans);
}
public static A
ayList deepCopy(A
ayList plans) throws CloneNotSupportedException
{
16- Complete the Code. (1 mark)
A
ayList copy = new A
ayList
();...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here