Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java only please: Provided code public class testShip { public static void main(String[] args) { //Create a cruise ship object Cruise sh1 = new Cruise(Celebrity

image text in transcribedimage text in transcribed

Java only please:

Provided code

public class testShip { public static void main(String[] args) { //Create a cruise ship object Cruise sh1 = new Cruise("Celebrity Equinox", 2009, "Meyer Werft", "Luxury Cruise", 2850); //Create a tanker ship object Tanker sh2=new Tanker("TI Oceania", 2003, "Daewoo Shipbuilding & Marine Engineering", "Oil Tanker", 503410); System.out.println(sh2); //Print tanker System.out.println(sh1); //Print cruise } // end main() } // end application class testShip

************************************************************************

public class Ship { private String name; // variable private int year; // variable private String builder; // variable public Ship() { setName(null); setyear(0); setBuilder(null); } // end null constructor public Ship(String name, int year, String builder) { setName(name); setyear(year); setBuilder(builder); } // end constructor public final void setName(String aName) { name = aName; } // end setName public final void setyear(int aYear) { year=aYear; } // end setYear public final void setBuilder(String aBuilder) { builder=aBuilder; } // end setBuilder public final String getName() { return name; } // end getName public final int getYear() { return year; } // end getYear public final String getBuilder() { return builder; } // end getBuilder public String toString() { String str=""; str += "Ship Name:"+getName(); str += "Built year:"+getYear(); str += "Built by:"+getBuilder(); return str; } // end toString } // end class Ship

Instructions: This is an extension of the work you did in Lab Exercise 03. Modify class Ship to be abstract. Write a simple test harness (requirement below) that will test the modified Ship hierarchy. Requirements: The only required change is to make the Ship class an abstract class. Do not make any other changes in Ship or the two subclasses. Write a new test harness named TestShipHierarchy.java to meet the following requirements: 1. Do not include a Scanner object. 2. Code all processing in the main method. 3. Declare an array to hold 4 objects 2 Tanker objects and 2 Cruise objects. a. Use a single array 4. Instantiate the objects using the provided test data (included below) 5. Write a single enhanced for loop to process the array objects. Expected output is included below

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 Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

Why should a consultants progress be regularly monitored?

Answered: 1 week ago