Question & Answer: y objects and an ArrayList of moveable objects. It should build an ArrayList of collectable objects for each good guy’s backpack. The m…..

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 guy’s backpack. The main program should go through all objects in each ArrayList and call their common methods (e.g., display(), move(), fight(), etc.).

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: y objects and an ArrayList of moveable objects. It should build an ArrayList of collectable objects for each good guy’s backpack. The m…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

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<CollectableObjects> backpack;

 

public GoodGuy(String name, String location, int speed, int health, String direction, int strength,

int intelligence, ArrayList<CollectableObjects> backpack) {

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<CollectableObjects> getBackpack() {

return backpack;

}

public void setBackpack(ArrayList<CollectableObjects> backpack) {

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;

}

 

}

Expert Answer

 

import java.util.ArrayList;

/**
*
* @author Sam
*/
public class Game {
public static void main(String[] args) {
ArrayList<StationaryObjects> stationaryObjects = new ArrayList<>();
ArrayList<MoveableObjects> moveableObjectses = new ArrayList<>();
ArrayList<CollectableObjects> collectableObjects;
stationaryObjects.add(new StationaryObjects(“tree1”, “home” , 5));
stationaryObjects.add(new StationaryObjects(“house”, “right” , 15));
stationaryObjects.add(new StationaryObjects(“well”, “right” , 8));
stationaryObjects.add(new StationaryObjects(“tank”, “home” , 18));
stationaryObjects.add(new StationaryObjects(“tree2”, “top” , 5));
collectableObjects = new ArrayList<>();
collectableObjects.add(new CollectableObjects(“Gold coin”, “home”, 14, CollectableObjects.Type.COIN));
collectableObjects.add(new CollectableObjects(“Silver coin”, “home”, 5, CollectableObjects.Type.COIN));
collectableObjects.add(new CollectableObjects(“revive”, “tree”, 25, CollectableObjects.Type.HEALTH_POTION));
collectableObjects.add(new CollectableObjects(“revive++”, “tree”, 50, CollectableObjects.Type.HEALTH_POTION));
collectableObjects.add(new CollectableObjects(“Chotu”, “well”, -15, CollectableObjects.Type.BOMB));
moveableObjectses.add(new GoodGuy(“hitasu”, “home”, 5, 50, “right”, 35, 8, collectableObjects));
moveableObjectses.add(new BadGuy(“Fotka”, “Well”, 15, 44, “left”, 40, 15));
moveableObjectses.add(new BadGuy(“Polka”, “tank”, 5, 25, “up”, 20, 20));
collectableObjects = new ArrayList<>();
collectableObjects.add(new CollectableObjects(“revive++”, “tree”, 50, CollectableObjects.Type.HEALTH_POTION));
collectableObjects.add(new CollectableObjects(“revive++”, “tree”, 50, CollectableObjects.Type.HEALTH_POTION));
collectableObjects.add(new CollectableObjects(“Chotu”, “well”, -25, CollectableObjects.Type.BOMB));
moveableObjectses.add(new GoodGuy(“Pacha”, “forest”, 15, 30, “botom”, 11, 15, collectableObjects));
moveableObjectses.add(new MoveableObjects(“Pod”, “home”, 1, 85, “all”));

System.out.println(“Stationary objects: “);
for (GameObjects object: stationaryObjects) {
object.display();
System.out.println(“———————————–“);
}
System.out.println(“|||||||||||||||||||||||||||||||||||||”);
System.out.println(“Moveable objects: “);
for (GameObjects object: moveableObjectses) {
object.display();
System.out.println(“———————————–“);
}
}

}

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;

}

@Override
public String toString() {
return “GameObjects{” + “name=” + name + “, location=” + location + ‘}’;
}

abstract void display();

}

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;

}

@Override
public String toString() {
return “StationaryObjects{” + “n” + super.toString() + “n” + “damagePoints=” + damagePoints + ‘}’;
}

@Override
void display() {
System.out.println(toString());
}

}

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;

}

@Override
public String toString() {
return “MoveableObjects{” + “n” + super.toString() + “n” + “speed=” + speed + “, health=” + health + “, direction=” + direction + ‘}’;
}

@Override
void display() {
System.out.println(toString());
}

}

class CollectableObjects extends GameObjects {

protected int value;

protected Type type;

@Override
void display() {
System.out.println(toString());
}

@Override
public String toString() {
return “CollectableObjects{” + “n” + super.toString() + “n” + “value=” + value + “, 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<CollectableObjects> backpack;

public GoodGuy(String name, String location, int speed, int health, String direction, int strength,

int intelligence, ArrayList<CollectableObjects> backpack) {

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<CollectableObjects> getBackpack() {

return backpack;

}

public void setBackpack(ArrayList<CollectableObjects> backpack) {

this.backpack = backpack;

}

@Override
public String toString() {
return “GoodGuy{” + “n” + super.toString() + “n” + “strength=” + strength + “, intelligence=” + intelligence + “, backpack=” + backpack.toString() + ‘}’;
}

@Override
void display() {
System.out.println(toString());
}

}

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;

}

@Override
public String toString() {
return “BadGuy{” + “n” + super.toString() + “n” + “defeatPoint=” + defeatPoint + “, meanFactors=” + meanFactors + ‘}’;
}

@Override
void display() {
System.out.println(toString());
}

}

Still stressed from student homework?
Get quality assistance from academic writers!