Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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 lower Deck, the upper Deck, 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, (c) a private attribute Sequence maneuverDeck, For each dock, do not forget the initalization! Example: private Stack lower Deck = new Stack(); or private Queue lower Deck = new ArrayDeque(); Do not forget to import the class Stack and/or the interface Queue and the class ArrayDeque. You can either use the Eclipse tool (light bulb that appears when needed) or add "import java.util.Stack;", "import java.util.Queue;", and "import java.util.ArrayDeque;" at the beginning of the Ferry class, right below package exercise;" d) a public method void embarkCar (String car), for embarking a car, at the end, print "Car car is parked in the lower deck (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 (f) a public method void disembarkCar (String car), for disembarking a car, i. for each car that has to leave and reenter the lower deck, print "Car car left and reentered the lower deck", ii. when car can disembark, print "Car car disembarked, iii. if you find out that car is not on board, print "Car car not on board (g) a public method void disembarkMotorbike(String motorbike), for disembarking a mo- torbike, i. for each motorbike that has to go to the maneuver deck, print Motorbike motorbike went to the manouver deck, ii. when motorbike can disembark, print "Motorbike motorbike disembarked, iii. if you find out that motorbike is not on board, print "Motorbike motorbike not on board" iv. 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" 3. Create a class Main and test your code (a) embark 4 cars, (b) embark 4 motorbikes, (c) disembark the 3rd embarked car, (a) disembark the 2nd embarked motorbike, (e) try to disembark a non embarked car, (f) try to disembark a non embarked motorbike

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago