Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Ships Study the UML diagram carefully. The green spots signify public. The red squares signify private. Superclass Ship is abstract because it contains the abstract

Ships Study the UML diagram carefully. The green spots signify public. The red squares signify private. Superclass Ship is abstract because it contains the abstract method purpose. This class also implements the Comparable interface to compare ships by tonnage. Ship also has a public static integer named numShips that is incremented in the constructor to serve as a counter for the number of ships. After coding these classes, write a program named TestShips that uses them as follows: Create an array of declared type Ship that contains at least six ships (two of each concrete subclass). You can make up all of the values for the data members of each ship. The Strings returned by purpose() can be determined by viewing the Possible Output below. Process the array in an enhanced for loop to display for each ship: The actual type using the getClass() method inherited from class Object. The output of the toString() method. The value returned by the purpose() method. Create a Ship arraylist from the array. Add one more CruiseShip instance to this arraylist. Sort the arraylist by tonnage from low to high. Report the value of the static numShips variable. Finish up by using an ordinary for loop to run the toString() method of the arraylist elements. Possible Output An unordered fleet of various ships

class chap11new.CruiseShip Ship name: Magic, year launched: 1998, GT 83338 2700 passenger capacity, operating in the Caribbean A holiday vessel for vacationers

class chap11new.CruiseShip Ship name: Titanic, year launched: 1912, GT 46328 2435 passenger capacity, operating in the Atlantic Ocean A holiday vessel for vacationers

class chap11new.CargoShip Ship name: Algeciras, year launched: 2020, GT 228283 Capacity of containers is 391 Hauling cargo across the seas

class chap11new.CargoShip Ship name: Seawise Giant, year launched: 1979, GT 260941 Capacity of crude oil is 564763 Hauling cargo across the seas

class chap11new.WarShip Ship name: USS Nimitz, year launched: 1972, GT 97000 Type: super carrier, operated by United States Navy A ship for defense or possibly attack

class chap11new.WarShip Ship name: USS Zumwalt DDG 1000, year launched: 2013, GT 15656 Type: destroyer, operated by United States Navy A ship for defense or possibly attack

Fleet size is now 7 Fleet sorted by tonnage after adding Symphony of the Seas

Ship name: USS Zumwalt DDG 1000, year launched: 2013, GT 15656 Type: destroyer, operated by United States Navy

Ship name: Titanic, year launched: 1912, GT 46328 2435 passenger capacity, operating in the Atlantic Ocean

Ship name: Magic, year launched: 1998, GT 83338 2700 passenger capacity, operating in the Caribbean

Ship name: USS Nimitz, year launched: 1972, GT 97000 Type: super carrier, operated by United States Navy

Ship name: Symphony of the Seas, year launched: 2018, GT 228081 6680 passenger capacity, operating in the Atlantic Ocean

Ship name: Algeciras, year launched: 2020, GT 228283 Capacity of containers is 391

> Ship chap 11new - name: String - year: int - tons: int S numShips: int Ship(String, int,int) getName(): String">

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

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions