Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please, implement in Java language: Implement an application that handles different kinds of trucks. All trucks share the same behavior of a regular truck but

Please, implement in Java language:
Implement an application that handles different kinds of trucks. All trucks share the same behavior of a regular truck but they provide different purposes in terms of the load they transport, such as a car carrier trailer carries cars, a logging truck carries logs, or refrigerator truck carries refrigerated items. Each truck only distinguishes itself from other trucks by its load. Inheritance is not applicable because all functionality is the same and there is no specialized behavior. The property of every truck is also the same and only differs by its data type. That is, the load of a truck is defined by an instance variable in the truck class. This instance variable is defined by a generic parameter that must have the Load interface as an upper bound. The Load interface represents any load a truck can carry. It is implemented by three different classes.
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.
A solution with blanks that should be filled in is given, please fill them:
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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What does stickiest refer to in regard to social media

Answered: 1 week ago