Java programing   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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java programing

 

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

<<Java Class>>
G'Ship
chap11new
a name: String
o year: int
o tons: int
numShips: int
fShip(String.int,int)
o getName(): String
o getYear():int
• getTons():int
s purpose(): String
O compareTo(Ship):int
o toString():String
<<Java Class>>
<<Java Class>>
<<Java Class>>
©Cargo Ship
©Cruise Ship
©WarShip
chap11new
chap11new
chap11new
a type: String
o nation: String
e cargo: String
в сарасity: int
fCargoShip(String.int,int, String.int)
o getCapacity().int
o equals(CargoShip):boolean
O purpose():String
o toString():String
* passengers: int
o zone: String
f CruiseShip(String.int,int, int, String)
o getPassengers().int
o getZone():String
o toString():String
o purpose():String
SWarShip(String.int,int,String,String)
o purpose():String
o toString():String
TT
Transcribed Image Text:<<Java Class>> G'Ship chap11new a name: String o year: int o tons: int numShips: int fShip(String.int,int) o getName(): String o getYear():int • getTons():int s purpose(): String O compareTo(Ship):int o toString():String <<Java Class>> <<Java Class>> <<Java Class>> ©Cargo Ship ©Cruise Ship ©WarShip chap11new chap11new chap11new a type: String o nation: String e cargo: String в сарасity: int fCargoShip(String.int,int, String.int) o getCapacity().int o equals(CargoShip):boolean O purpose():String o toString():String * passengers: int o zone: String f CruiseShip(String.int,int, int, String) o getPassengers().int o getZone():String o toString():String o purpose():String SWarShip(String.int,int,String,String) o purpose():String o toString():String TT
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education