I'm trying to code a system to determine the type of a weapon and the damage of the weapon for a video game. I'm trying to instantiate two weapons with different stats, but when I use the method getType();
, they return the same thing.
I tried using an ArrayList, but grabbing the type of the weapon from something such as (arraylist name here).get(0).getType();
and (arraylist name here).get(1).getType();
still return "AK-47"
.
ArrayList<Weapon> weapons = new ArrayList<Weapon>();
Weapon weapon = new Weapon("Desert Eagle", 5);
Weapon weapon2 = new Weapon("AK-47", 3);
weapons.add(weapon);
weapons.add(weapon2);
System.out.println(weapon.getType());
System.out.println(weapon2.getType());
Methods:
public class Weapon {
static String type;
static int damage;
public Weapon(String type, int damage) {
Weapon.type = type;
Weapon.damage = damage;
}
public static String getType() {
return type;
}
}
I want weapon.getType();
to return "Desert Eagle"
and weapon2.getType();
to return "AK-47"
.
I know it should be a simple answer, but I'm probably just over-complicating this for myself haha. Any help is appreciated, thanks!