Question
Into to Java Modify the Player program below with the following: Add the following PRIVATE data: ArrayList inventory (default: new ArrayList ()) Add the following
Into to Java
Modify the Player program below with the following:
Add the following PRIVATE data: ArrayList inventory (default: new ArrayList<>())
Add the following PUBLIC methods: void addItem(Item item): adds an item to inventory.
boolean useItem(int index): If the index is in bounds AND the Item at inventory.get(index) is an instance of Food: Add the heals from the item to the Players health Remove the item from the inventory (remove() method of ArrayList) Return true Otherwise, return false.
void printInventory(): Print INVENTORY: using System.out.println(). Loop through your inventory: Print Item + i using System.out.println (where i is the index in the loop) Print the Item (System.out.println(inventory.get(i)))
Program:
public class Player { private int X; private int Y; private int array[]; private int Health; private Weapon currentWeapon; public Player() { array = new int[2]; array[0] = 0; array[1] = 0; this.X = 0; this.Y = 0; } public Player(int x, int y){ array = new int[2]; array[0] = x; array[1] = y; this.X = x; this.Y = y; } public int getX() { return X; } public int getY() { return Y; } public int getHealth() { return Health; } public Weapon getCurrentWeapon() { return currentWeapon; } public void setX(int x) { X = x; } public void setY(int y) { Y = y; } public void setHealth(int health) { Health = health; } public void setCurrentWeapon(Weapon currentWeapon) { this.currentWeapon = currentWeapon; } }
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