Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In JAVA shipinfo.txt is as follows: Name: Years Build: Type : Capacity (Cargo or Passengers) Great White: 1995: Ship Bermuda: 2001: Ship Princess Diamond: 2002:
In JAVA
shipinfo.txt is as follows:
Name: Years Build: Type : Capacity (Cargo or Passengers) Great White: 1995: Ship Bermuda: 2001: Ship Princess Diamond: 2002: CruiseShip: 3600 Beast: 2020: CargoShip: 500000 Princess Grand: 2017: CruiseShip: 2700 Princess Hope: 1999: CruiseShip: 1500 Monster: 2002: CargoShip: 200000 Wall: 2015: CargoShip: 2340000 Love Boat: 2005: Ship Turbo: 2013: CargoShip: 1540000Q1: (13 points: 3 points for reading the data in properly, 3 points on proper exception handlings and 7 points for setting up the correct inheritance relationships) Ship, Cruise Ship and Cargoship classes Design a Ship class with the following members: . A field for the name of the ship (string) A field for the year that the ship was build (string) A constructor and appropriate accessors and mutators. A toString method that display the ship's name and the year it was built. Design a Cruise Ship class that extends from the Ship class. The Cruise Ship class should have the following additional members: . . . A field for the maximum number of passengers (int) A field for the maximum number of rooms (int). Each room can accommodate two occupants, which means maximum number of rooms are defined by passengers/2. A constructor and appropriate accessors and mutators. A toString method that overrides the toString method from the super class. The Cruise ship class's toString method should display the ship's name, maximum number of passengers, number of rooms available. Design a CargoShip class that extends from the Ship class. The CargoShip class should have the following additional members: A field for the cargo capacity in tonnage (int) A constructor and appropriate accessors and mutators. A toString method that overrides the toString method from the super class. The Cargoshir. class's toString method should display the ship's name, ship's cargo capacity 0 Demo class: Demonstrate the classes in a program that has a Ships array. Read the data in from the shipinfo.txt file (provided separately). Assign various Ship, Cruise Ship and Cargoship objects to the array elements based on the different data provided (10 different types of ships). The program should then step through the array, calling each object's toString method and display the appropriate information via terminal. You also need to make sure to protect your code from file not found exception. Please submit all codes in one zipped file + screenshot of the output. Q2. Expanding from Q1. (7 points). Using the Comparable interface and the int compareTo(Object X) interface method to sort the Ships array based on the year it was build. Display the sorted result using the toString method but with youngest ship first. Please submit all codes in one zipped file + screenshot of the output
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