Question
make a program that does the following: 1) give an example of an abstract class named SpaceShip . It will include: - a data
make a program that does the following:
1) give an example of an abstract class named SpaceShip. It will include:
- a data member named numEngines of type int
- a data member named name of type String
- an abstract method:
void ShowSpeed ();
2) give an example of a class named ScoutShip that extends SpaceShip. It will include:
- no-arg constructor that sets numEngines=1
- a constructor that takes numEngines as an argument
- both constructors should set the name of the ship to "Scout"
- a ShowSpeed() method that prints a line of output with the name of the ship and the speed it can fly. For each engine the ship can fly 2 warp factor (example: a ship with 4 engines can fly at speed 8 warp factor).
3) give an example of a class named ExplorerShip that extends SpaceShip. It will include:
- no-arg constructor that sets numEngines=2
- a constructor that takes numEngines as an argument
- both constructors should set the name of the ship to "Explorer"
- a ShowSpeed() method that prints a line of output with the name of the ship and the speed it can fly. For each engine the ship can fly 2 warp factor (example: a ship with 4 engines can fly at speed 8 warp factor).
4) give an example of a TestShip.java file with a main() method. The main method should:
- create an instance of the Scout ship class with 1 engine (use the default constructor).
- create an instance of the Explorer ship class with 3 engines.
- call the ShowSpeed() method on both objects. Your output should look something like:
Scout ship can fly at speed 2 warp factor
Explorer ship can fly at speed 6 warp factor
5) Draw the UML diagram for all 3 classes.
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