Note: This lab is not so much related to the above lesson as it is a prep for the next lesson on the Factory Design Pattern.
Create the classes shown at the bottom of this page in a new java project using the IDE of your choice. Then create a new class called VideoGame. Inside your VideoGame class create a method called addAliens which creates ten new Aliens with each one being chosen from one of the four subtypes shown and adds them to your video game. (You should simulate this addition process by creating an ArrayList and adding the Aliens to this ArrayList). Be sure to print the names of the ten aliens you have added. Each Alien should be created by choosing an Alien subtype (SquidAlien, MonkeyAlien, TigerAlien or RatAlien) randomly.
Hints: Use an enum and a switch statement in your method.
import java.util.Random;
public class Alien {
private final String NAME;
private static Random r = new Random();
// NAME will consist of type and 1 or 2 digit random number
public Alien(String type) {
this.NAME = type + r.nextInt(100);
}
public String getName() {
return this.NAME;
}
public String toString() {
return this.NAME;
}
}
public class SquidAlien extends Alien {
public SquidAlien() {
super("Squid");
}
}
public class MonkeyAlien extends Alien {
public MonkeyAlien() {
super("Monkey");
}
}
public class TigerAlien extends Alien {
public TigerAlien() {
super("Tiger");
}
}
public class RatAlien extends Alien {
public RatAlien() {
super("Rat");
}
}