Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me code my items class also my extended classes as well like items extends weapon, armour, craftedItems, etc below is also my

Can someone help me code my items class also my extended classes as well like items extends weapon, armour, craftedItems, etc below is also my player class that i have code that realtes to items if someone could please help as soon a spossible im having some trouble

public class Player { // instance variables - replace the example below with your own private Stackrooms; private String name; private ArrayList items; private int maxVolume; private int hp; private int damage;

/** * Constructor for objects of class Player */ public Player(String name) { // initialise instance variables this.name = name; }

public Room getCurrentRoom() { // put your code here return rooms.peek(); } public void goBack() { this.rooms.pop(); } public void goNext(Room room) { this.rooms.push(room); } public Item getItem(String name) { for(Item i : items) { if(i.getName().equals(name)) { return Item; } } } public pickUp(Item item) { if(item instanceof Armor) { Armor armor = (Armor) item; hp += armor.getHp(); } else if(item instanceof Weapon) { Weapon weapone = (Weapon) item; damage += damge.getDamage(); } else if(item instanceof Bag) { Bag bag = (Bag) item; maxVolume += bag.getWeight(); } items.add(item); } public Item drop(String name) { for(Item item : items) { if(item.getName().equals(name)) { if(item instanceof Armor) { Armor armor = (Armor) item; if(hp > armor.getHp()); { hp -= armor.getHp(); items.remove(armor); return armor; } } else if(item instanceof Weapon) { Weapon weapon = (Weapon) item; damage -= damage.getDamge(); items.remover(weapon); return weapon; } else if(item instanceof Bag) { } else { items.remove(item); return item ; } } } return null; } public boolean takeDamage(int damage) { this.hp -= damage; return this.hp < 1; } } student submitted image, transcription available below

Weapon Item + damage: int +name: String + description: String + Weapon(String, String, int): Weapon + getDamage): int Armor + hp: int + Item(String, Strinng): Item + getName:String +getDescription(): String +getWeight0: int Extends +Armor(String, String, int): Armor +getHp): int Bag Extends + volume: int Bag(String, String, int): Bag getVolume(): int Extends Crafteditem + firstltem: Item + secondltem: Item Craftedltem(String, String, Item first, Item second): Craftedltem Weapon Item + damage: int +name: String + description: String + Weapon(String, String, int): Weapon + getDamage): int Armor + hp: int + Item(String, Strinng): Item + getName:String +getDescription(): String +getWeight0: int Extends +Armor(String, String, int): Armor +getHp): int Bag Extends + volume: int Bag(String, String, int): Bag getVolume(): int Extends Crafteditem + firstltem: Item + secondltem: Item Craftedltem(String, String, Item first, Item second): Craftedltem

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago