Question
// This is the interface that each of your Box classes will implement. // As you can see, this interface allows different kinds of boxes
// This is the interface that each of your Box classes will implement.
// As you can see, this interface allows different kinds of boxes to
// store and return their volume and weight using any class types.
interface Parcel
public VolumeType getVolume();
public WeightType getWeight();
}
// TODO: implement the MetricBox class below to:
// 1) correctly implement the Parcel interface above
// 2) force the volume and weight returned from any MetricBox to be type Double
// 3) enable the checks in the main method below to compile and run
class MetricBox {}
// TODO 2/3: implement the EnglishBox class below to:
// 1) correctly implement the Parcel interface above
// 2) force the volume returned from any EnglishBox to be type String, but
// allow the weight to be different for different EnglishBoxes
// 3) enable the checks in the main method below to compile and run
class EnglishBox {}
// TODO 3/3: implement the UniformBox class below to:
// 1) correctly implement the Parcel interface above
// 2) force the weight and volume retrieved from any UniformBox to be of a single
// consistent generic type: so that the volume and weight cannot be different types
// 3) enable the checks in the main method below to compile and run
class UniformBox {}
public class GenericsActivity {
public static void main(String[] args) {
String typesChecked = "";
// Checks for the MetricBox type:
// Parcel
// if( !(m.getVolume().toString()+m.getWeight().toString()).equals("3.04.0") )
// System.out.println("m does not include expected contents.");
// typesChecked += "MetricBox ";
// Checks for the EnglishBox type:
// Parcel
// if( !(e1.getVolume().toString()+e1.getWeight().toString()).equals("large5") )
// System.out.println("e1 does not include expected contents.");
// Parcel
// if( !(e2.getVolume().toString()+e2.getWeight().toString()).equals("mediumheavy") )
// System.out.println("e2 does not include expected contents.");
// typesChecked += "EnglishBox ";
// Checks for the UniformBox type:
// Parcel
// if( !(u1.getVolume().toString()+u1.getWeight().toString()).equals("6.02.0") )
// System.out.println("u1 does not include expected contents.");
// Parcel
// if( !(u2.getVolume().toString()+u2.getWeight().toString()).equals("smalllight") )
// System.out.println("u2 does not include expected contents.");
// typesChecked += "UniformBox ";
System.out.println("Checks complete for: "+typesChecked);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started