Question: Implement a system simulating a ferry boat that makes trips with several stops. The ferry has only one opening on the front, which is used

Implement a system simulating a ferry boat that makes trips with several stops. The ferry has only one opening on the front, which is used for embarking and disembarking cars and motorbikes.

The lower deck of the ferry is used for parking cars. It is horseshoe-shapd, meaning that the emarking cars get in through the opening, drive along the lower deck until the end and find themselves facing the opening from the inside. The lower deck is very narrow so the cars must leave in the same order as they got in. If a car in the middle has to disembark, each car in front of it will leave the lower deck and reenter it immediatly from the embarking side.

The upper deck is used for parking motorbikes. It is straight and very narrow, meaning that the first motorbike to get in is the last one to get out. In case a motorbike in the middle has to disembark, the motorbikes standing in front of it are temporary stocked in the maneuver deck, then moved back to the upper deck such that they are in the same order as before.

In the text of the exercise, it is not specified whether you have to use a Stack or a Queue to implement the lowerDeck, the upperDeck, and the maneuverDeck. You must choose which of the two sequence types is the suitable one by replacing Sequence with Stack or Queue in your implementation. Only use the methods described in the Data Structures for Sequences section above!

Cars and Motorbikes are both modeled as a String contraing the license plate. Do not forget to replace car and motorbike with the respective license plates in the text you print.

  1. Create a new Java project and add a package named exercise in it (you should not have problems doing this by now, if you have troubles take a look at the previous sheets)

  2. Create a class Ferry containing the following: (a) a private attribute Sequence lowerDeck,

    (b) a private attribute Sequence upperDeck, 4

(c) a private attribute Sequence maneuverDeck, For each dock, do not forget the initalization! Example: private Stack lowerDeck = new Stack(); or private Queue lowerDeck = new ArrayDeque(); Donotforgettoimporttheclass Stackand/ortheinterfaceQueueandtheclassArrayDeque. You can either use the Eclipse tool (lightbulb that appears when needed) or add import java.util.Stack;,import java.util.Queue;,andimport java.util.ArrayDeque; at the beginning of the Ferry class, right below package exercise;

  1. (d) a public method void embarkCar(String car), for embarking a car, at the end, print Car car is parked in the lower deck

  2. (e) a public method void embarkMotorbikes(String motorbike), for embarking a motor- bike,

    at the end, print Motorbike motorbike is parked in the upper deck

  3. (f) a public method void disembarkCar(String car), for disembarking a car,

    1. for each car that has to leave and reenter the lower deck, print Car car left and reentered the lower deck,

    2. when car can disembark, print Car car disembarked,

    3. if you find out that car is not on board, print Car car not on board

  4. (g) a public method void disembarkMotorbike(String motorbike), for disembarking a mo- torbike,

i.

ii. iii.

iv.

3. Create a

for each motorbike that has to go to the maneuver deck, print Motorbike motorbike went to the manouver deck, when motorbike can disembark, print Motorbike motorbike disembarked, if you find out that motorbike is not on board, print Motorbike motorbike not on board

for each motorbike that has to go back from the maneuver deck back to the upper deck, print Motorbike motorbike went back to the upper deck

class Main and test your code

(a) embark 4 cars, (b) embark 4 motorbikes,

(c) disembark the 3rd embarked car, (d) disembark the 2nd embarked motorbike,

(e) try to disembark a non embarked car, (f) try to disembark a non embarked motorbike.

JAVA QUESTION

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!