Question
Question 5 [30 points]: (a) A Ship has an id and a number of containers. The id cannot be modified after it is initialized to
Question 5 [30 points]: (a) A Ship has an id and a number of containers. The id cannot be modified after it is initialized to a non-default value . Write an appropriate Ship class that enables: Ship objects to be assigned unique consequtive ids starting at id 2514. The counting of total number of containers for all Ship objects. The class must have: All its variables to be private A one-argument constructor that throws an appropriate exception A copy constructor Appropriate get-methods An appropriate set method that throws an appropriate exception. An appropriate toString method (b) A ShipCompany has private numberOfShips variable and a private array of Ship objects. Write an appropriate ShipCompany class that has: A one-argument constructor that takes the maximum number of ships that the ship company can own. The constructor throws an appropriate exception if the argument is less than 10. addShip method. The method adds a new ship to the array of Ship objects. The method throws an appropriate exception. Your method must have no reference leaks. getShipArray method. The method returns the array of ship objects. Your method must have no reference leaks. (c) Write an appropriate ShipCompanyDriver class that performs the following in order: Creates a ShipCompany object that can have a maximum of 60 ships. Adds at least four Ship objects to the ShipCompany object. Decreases by 7 the number of containers of the last Ship object in the array of Ship objects. [Your code must be general; it must work for any array length] Displays the total number of containers for all ships. [The counting must neither be done in the driver class nor use loops anywhere in the program.] Displays the Ship array. Determines whether the ship with ID 2530 exists in the array or not by displaying an appropriate message. Sample program run: Total number of containers: 48983 Ship list: [ID#: 2514, Number of containers: 13500] [ID#: 2515, Number of containers: 11000] [ID#: 2516, Number of containers: 15000] [ID#: 2517, Number of containers: 9483] The ship 2530 does not exist
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started