Question
Using Java complete a main method for the following code. The main program (aka test program) should build an ArrayList of stationary objects and an
Using Java complete a main method for the following code.
The main program (aka test program) should build an ArrayList of stationary objects and an ArrayList of moveable objects. It should build an ArrayList of collectable objects for each good guys backpack. The main program should go through all objects in each ArrayList and call their common methods (e.g., display(), move(), fight(), etc.).
import java.util.ArrayList;
abstract class GameObjects {
protected String name;
protected String location;
public String getLocation() {
return location;
}
public GameObjects(String name, String location) {
super();
this.name = name;
this.location = location;
}
public void setLocation(String location) {
this.location = location;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class StationaryObjects extends GameObjects {
protected int damagePoints;
public int getDamagePoints() {
return damagePoints;
}
public StationaryObjects(String name, String location, int damagePoints) {
super(name, location);
this.damagePoints = damagePoints;
}
public void setDamagePoints(int damagePoints) {
this.damagePoints = damagePoints;
}
}
class MoveableObjects extends GameObjects {
protected int speed;
protected int health;
protected String direction;
public MoveableObjects(String name, String location, int speed, int health, String direction) {
super(name, location);
this.speed = speed;
this.health = health;
this.direction = direction;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public int getHealth() {
return health;
}
public void setHealth(int health) {
this.health = health;
}
public String getDirection() {
return direction;
}
public void setDirection(String direction) {
this.direction = direction;
}
}
class CollectableObjects extends GameObjects {
protected int value;
protected Type type;
public enum Type {
COIN,
HEALTH_POTION,
AXE,
SORWD,
MACE,
BOMB;
}
public CollectableObjects(String name, String location, int value, Type type) {
super(name, location);
this.value = value;
this.type = type;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
}
class GoodGuy extends MoveableObjects {
protected int strength;
protected int intelligence;
protected ArrayList
public GoodGuy(String name, String location, int speed, int health, String direction, int strength,
int intelligence, ArrayList
super(name, location, speed, health, direction);
this.strength = strength;
this.intelligence = intelligence;
this.backpack = backpack;
}
public int getStrength() {
return strength;
}
public void setStrength(int strength) {
this.strength = strength;
}
public int getIntelligence() {
return intelligence;
}
public void setIntelligence(int intelligence) {
this.intelligence = intelligence;
}
public ArrayList
return backpack;
}
public void setBackpack(ArrayList
this.backpack = backpack;
}
}
class BadGuy extends MoveableObjects {
protected int defeatPoint;
protected int meanFactors;
public BadGuy(String name, String location, int speed, int health, String direction, int defeatPoint,
int meanFactors) {
super(name, location, speed, health, direction);
this.defeatPoint = defeatPoint;
this.meanFactors = meanFactors;
}
public int getDefeatPoint() {
return defeatPoint;
}
public void setDefeatPoint(int defeatPoint) {
this.defeatPoint = defeatPoint;
}
public int getMeanFactors() {
return meanFactors;
}
public void setMeanFactors(int meanFactors) {
this.meanFactors = meanFactors;
}
}
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