Question
In this question you are to create a Ship class and a CruiseShip class (derived from the Ship class). All instructions are in comments in
In this question you are to create a Ship class and a CruiseShip class (derived from the Ship class). All instructions are in comments in the classes. You also need to complete the main method. You have been asked to write methods that are not used in this program - write them anyway because I will grade them. If in doubt, ask!.
Test3.java
public class Test3 {
public static void main(String[] args) { Scanner scnr = new Scanner(System.in); //create two cruiseships String name = scnr.next(); int yearBuilt = scnr.nextInt(); int capacity = scnr.nextInt(); CruiseShip s1 = new CruiseShip(name, yearBuilt, capacity); name = scnr.next(); yearBuilt = scnr.nextInt(); capacity = scnr.nextInt(); CruiseShip s2 = new CruiseShip(name, yearBuilt, capacity); //write code to output which is larger //you must use compareTo //do not put them into an arrayList or array. Do not sort using a sort such as Collections sort. if( //use compareTo here ) System.out.println(s1.getName() + " is larger"); else if ( //use compareTo here ) System.out.println(s2.getName() + " is larger"); else System.out.println("They are the same size"); } }
Ship.java
//ship has attributes //name (a String) //and //yearBuilt (an int) //write constructors, ALL mutators and accessors, and a writeOutput . //even though these are mostly unused in this program, you need to write them to get a grade public class Ship { }
CruiseShip.java
/* *CruiseShip inherits from Ship and has an attribute called capacity (an int) which is the maximum number of passengers write all constructors, accessors, and mutators write a writeOutput method. Write a compareTo that compares according to the capacity
*/
public class CruiseShip { }
Rubric:
Ship class: attributes, constructors, accessors, mutators
Ship class: writeOutput
CruiseShip class: correctly derived from Ship class
CruiseShip class: constructors and writeOutput correctly depend on Ship class
CruiseShip class: accessors, mutators
CruiseShip class : compareTo correctly written
Main: correct use of compareTo
Correct 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