Reference no: EM131602761
Polymorphism
After you release the revised Super Happy Fun Cute Creatures World Traveler from Homework 3, the game gains worldwide popularity. Kids and adults from Europe to Asia to North America are playing it, and you even get fan mail from one random scientist down in Antarctica.
But a game company's work is never done! You decide it's time to break into the niche market of space combat simulators. The basic idea behind your sim is that you control a spaceship that can fire different types of weapons. Each weapon has its own attack damage and load time. (Generally speaking, longer loading weapons should give you higher damage, and vice versa.)
1. Implement the following classes and interfaces:
a. An interface Drawable that contains a single method, draw(). This interface will be implemented by any classes representing game objects that you want to draw on the screen. This makes it so the game engine (which you don't need to write for this assignment...) can treat every object you want to show on the screen as type Drawable, and it can simply call draw() on each of those objects to renderit.
b. A class Spaceship that implements Drawable. For now, the draw() method can just display some text - make this as simple or elaborate as youwant!
c. An abstract class Weapon that contains instance variables for damage and load time. Weapon should also contain an abstract method fire(), and it should implement a Comparable interface by providing a compareTo(Comparable c) method based on the load time. Finally, Weapon should implement Drawable with the abstract methoddraw().
d. A Laser subclass of Weapon. Laser must implement the fire() and draw() methods inheritedfrom
Weapon. Both methods can just display some text - be as simple or elaborate as you want!
e. A SingularityCannon subclass of Weapon. SingularityCannon must implement the fire() and draw() methods inherited from Weapon. Both methods can just display some text - be as simple or elaborate as youwant!
Include some way to specify the damage and load time of your Weapon objects. This could be via setter methods, constructors, randomly assigned values in some range, or some combination thereof.
Attachment:- Inheritance.zip