Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java Q1: (13 points: 3 points for reading the data in properly, 3 points on proper exception handlings and 7 points for setting up the

java

Q1: (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, CruiseShip 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 ships name and the year it was built.

Design a CruiseShip class that extends from the Ship class. The CruiseShip 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 CruiseShip classs toString method should display the ships 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 CargoShip classs toString method should display the ships name, ships cargo capacity

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, CruiseShip 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 objects 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.

Shipinfo.txt

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: 1540000

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions

Question

LO2 Explain the major laws governing employee compensation.

Answered: 1 week ago