Question
Please help with JAVA. Fill in the blanks. Create the following types: Load : Create an interface called Load. The interface is empty. Car :
Please help with JAVA. Fill in the blanks.
Create the following types:
Load: Create an interface called Load. The interface is empty.
Car: Create a class named Car that implements the Load interface. This class is empty but you may add properties.
TreeLog: Create a class named TreeLog that implements the Load interface. This class is empty but you may add properties.
RefrigeratedStorage: Create a class named RefrigeratedStorage that implements the Load interface. This class is empty but you may add properties.
Truck: A final class named truck. Instances (not the class itself!) of this Truck class should be specialized in the way they handle freight transport. The specialized freight is accomplished by the class using a generic type parameter in the class definition. The generic parameter must have the Load interface as its upper bound. Each truck carries a freight which is defined by an instance variable of ArrayList with elements of the generic type parameter. Do not use the type Load interface for the elements. The exact type of the load instance variable is determined at instantiation time when the variable of the truck class is declared. The class has the following properties:
A member variable of type ArrayList named freight. The ArrayList stores objects of the generic type defined in the class definition.
A method named load(..) that "loads" one object onto the truck and adds it to the freight list. The object is passed in as an argument and must be of the generic type defined in the class definition.
A method named unload(...) which expects an index of the element in the freight list to be removed. The removed element is returned by the method.
interface \} class \} class TreeLog \} class RefrigeratedStorage \} public final class Truck private ArrayList freight = new ArrayList (); public void load(T item) \{ this.freight.add(item); \} public unload(int index) \{ return this.freight.get(index); \} \}
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