Question
Create a public class named Ship with fields for displacement and length. Include a constructor that requires parameters for both fields and get and set
Create a public class named Ship with fields for displacement and length. Include a constructor that requires parameters for both fields and get and set methods for both fields. Include a toString method that displays the value of both fields.
Create two public child classes of the Ship class named WindPoweredShip and PropellerPoweredShip.
The WindPoweredShip class should have a field named numberMasts and a toString() method that shows the value of all of its fields. The WindPoweredShip should have a constructor with parameters for displacement, length, and numberMasts. Include get and set methods for all fields.
The PropellerPoweredShip class should have a field named numberPropellers and a toString() method that shows the value of all of its fields. The PropellerPoweredShip class should have a constructor with parameters for displacement, length, and numberPropellers. Include get and set methods for all fields.
Write a public class named ShipDemo that creates two WindPoweredShip objects and two PropellerPoweredShip objects. All four objects should be stored in a single array. The program should print each object in the array.
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