Vehicle Inheritance
For this task you will be creating a series of classes representing different types of Vehicles. They all have a move () method that returns the sound the vehicle makes. All Vehicles also have a make, which is accessible with the getMake() method that returns a String.
# sound:String
+ gettravelUnc
LandVehicle
All of the land vehicles have a number of wheels, accessible with a countWheels () method that returns an int.
WaterVehicle
In all of the water vehicles, we need to include whether it can travel under water accessible with a getTravelsUnderwater () method that returns a boolean.
Car is a type of land vehicle. It has 4 wheels, a make and a year. When the car moves, it should return “vroom vroom”. When you print out a Car object, the output should be in the format:
Bikes have 2 wheels, a make and a total distance travelled. When the bike moves, it should return
“RrrrrRrrrRrrRRrrrrrrrr”. When you print out a Bike object, the output should be in the format:
Yacht is a type of water vehicle. Yachts have a make, a number of seats and it can’t travel under water. When the Yacht moves, it should return “sploosh splash”. When you print out a Yacht object, the output should be in the format:
Submarine is a type of water vehicle. Submarines have a make, a number of oxygen cylinders and it can travel under water. When the submarine moves, it should return “joop”. When you print out a submarine object, the output should be in the format:
Task 5 – EasyQueue
Implement the EasyQueue interface with the MyQueue class. You can use either a linked list or a dynamic array to implement the data structure.
A queue is a specialised form of list in which you can only get and remove the first element of the list and add element only at the end of the list.
The class should work with the following code:
EasyQueue queue = new MyQueue () ;
NB: You are NOT allowed to import anything from the standard library for this task. The data structure must be of your own creation, not a modified form of a pre-existing class.
public interface EasyQueue{
* Returns true if the queue is empty, else false.
* @return whether the queue is empty
public boolean isEmpty();
* Removes all elements from the queue.
public void clear();
* Returns the first element, null if empty.
* @return the first element
public String peek();
* Returns and removes the first element, null if empty.
* @return the first element
public String dequeue();
* Appends the element to the end of the queue. Does nothing if the element is null.
* @param elem the element to be added
public void enqueue(String elem);
* Returns the size of the queue
* @return the size of the queue
public int size();
* Returns true if the queue contains the given element.
* @return whether the element is present
public boolean contains(String elem);