Question: Freight has a constructor and private instance variables: address, the address the freight is to be sent to as a String dateSent, the date the

Freight has a constructor and private instance variables:
address, the address the freight is to be sent to as a String
dateSent, the date the freight was sent as a String.
It also has a getter method for address and getter and setter methods for dateSent.
a.In this part you will complete the class Parcel, which already has the following private fields:
weight, of type double, the weight of the parcel in kilos,
width, of type int, which holds the width of the parcel in cms,
length, of type int, which holds the length of the parcel in cms,
height, of type int, which holds the height of the parcel in cms.
In addition, there are three public integer class constants:
LENGTH_LIMIT, the maximum length of a parcel that can be carried,
SIZE_LIMIT, the maximum size (derived from a formula supplied by the courier company),
WEIGHT_LIMIT, the maximum weight in kilos.
The class has a getter method for weight as well as equals and toString methods, which are initially commented out.
i.Alter the header of Parcel so it inherits from Freight and add a public constructor to the class Parcel with the signature:
Parcel(String, double, int, int, int)
The constructors first parameter is used to set the address, and the other four parameters to set the values of the four instance fields of Parcel in the order described above.
The field dateSent should be set to an empty string.
Uncomment the provided methods equals and toString.
(4 marks)
ii.Write a public class method called getOrderedSides which takes arguments of the width, length and height of the parcel and returns an ArrayList of Integer containing the values of the three sides of the parcel, ordered from smallest to largest.
(5 marks)
iii.Write a public instance method getLongestSide which returns the longest side of the parcel.
(3 marks)
iv.Write a public instance method getParcelSize which takes no arguments and returns the size of the parcel using the formula: (shortest side + next shortest side) x 2+ longest side.
(3 marks)
v.Write a public instance method isWithinLimits that returns true if the longest side of the parcel is less than or equal to LENGTH_LIMIT, the size of the parcel is less than or equal to SIZE_LIMIT and the weight of the parcel is less than or equal to WEIGHT_LIMIT.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!