Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A Harbor has enough anchor space for 5 ships and one pier for loading/unloading. A Ship comes as either a CruiseShip or a CargoShip. 1.1

A Harbor has enough anchor space for 5 ships and one pier for loading/unloading. A Ship comes as either a CruiseShip or a CargoShip.

1.1 Ship

Design a Ship class that has the following members:

A field for the name of the ship (a string)

A field for the year that the ship was built (an int)

A constructor and appropriate accessors and mutators, as well as constructors for no built year provided (set to -1) or no name provided (set to ), or neither provided.

A toString method that displays the ships name and the year it was built. If the ship has no name or a negative year of build, unknown should be used instead.

1.2 CruiseShip

Design a CruiseShip class that is derived from the Ship class. The CruiseShip class should have the following members:

A field for the maximum number of passengers (an int)

A constructor and appropriate accessors and mutators, as well as a constructor with only passengers.

A toString method that overrides the according method in the superclass. The CruiseShip classs toString method should additionally display the maximum number of passengers.

1.3 CargoShip

Design a CargoShip class that is derived from the Ship class. The CargoShip class should have the following members:

A field for the cargo capacity in tonnage (an int)

A constructor and appropriate accessors and mutators, as well as a constructor with only tonnage.

A toString method that overrides the according method in the superclass. The CargoShip classs toString method should additionally display the ships cargo capacity.

1.4 Harbor

The Harbor class implements the following interfaces:

Listing 1: Interface definitions.

1 public interface LoadingPier {

2 public boolean pierIsBusy(); // Whether or not a ship is using the pier.

3 public boolean startPier(int anchorSpot); // Put a ship from anchor at the pier.

4 public boolean donePier(); // Ship is done at the pier, put into anchor spot.

5 }

6

7 public interface Anchoring {

8 boolean anchorShipInHarbor(Ship ship);

9 // Sails a ship into harbor.

10 void sailShipFromHarbor(int anchorSpot);

11 // Ship sails away from anchor spot.

12 int shipsInHarbor();

13 // How many ships are there?

14 }

Note that there is only one harbor with a fixed space. The Harbor will require a toString method that calls each ships respective toString method, i.e., lists all the ships currently anchored and the one that might be at the pier. If a ship tries to enter the harbor, but there are no anchor spots available, a boolean false should be returned. If the pier is busy, no other ships can be using it. Ships need to anchor before and after they use the pier.

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

Recommended Textbook for

Database Systems For Advanced Applications 15th International Conference Dasfaa 2010 International Workshops Gdm Benchmarx Mcis Snsmw Diew Udm Tsukuba Japan April 2010 Revised Selected Papers Lncs 6193

Authors: Masatoshi Yoshikawa ,Xiaofeng Meng ,Takayuki Yumoto ,Qiang Ma ,Lifeng Sun ,Chiemi Watanabe

2010th Edition

3642145884, 978-3642145889

More Books

Students also viewed these Databases questions