-
Notifications
You must be signed in to change notification settings - Fork 2
/
HealItem.java
65 lines (57 loc) · 1.84 KB
/
HealItem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* HealItem.java
* This class represents an item that is capable of healing the player
* @author Emma Shumadine, Lily Orth-Smith, Rachel Zhang (primary)
*/
public class HealItem extends Item {
private int hp;
/**
* Creates a healing item
* @param n the name
* @param d the description
* @param hp the amount that the item heals
*/
public HealItem(String n, String d, int hp) {
super(n, d);
this.hp = hp;
}
/**
* Returns the HP of the item
* @return the HP of the item
*/
public int getHp() {
return hp;
}
/**
* Sets the HP that the item heals
* @param hp the HP
*/
public void setHp(int hp) {
this.hp = hp;
}
/**
* Returns a new HealItem with the same name, description, and hp
* @return a cloned version of this HealItem
*/
public HealItem clone() {
return new HealItem(name, description, hp);
}
/**
* Returns true if the items have the same name, description and hp
* @param healItem the item to be compared
* @return true if the items have the same name, description, and hp
*/
public boolean equals(HealItem healItem) {
return (super.equals(healItem) && (hp == healItem.getHp()));
}
public static void main(String[] args) {
Item rock = new Item("Rock", "Does nothing.");
HealItem healRock = new HealItem("Rock", "Heals", 5);
HealItem healRock2 = new HealItem("Rock", "Heals", 5);
HealItem superHealRock = new HealItem("Rock", "Heals", 20);
System.out.println("Does rock equal healRock? (false): " + rock.equals(healRock));
System.out.println("Does healRock equal healRock2? (true): " + healRock.equals(healRock2));
System.out.println("Does superHealRock equal healRock? (false): " + superHealRock.equals(healRock));
System.out.println("Does superHealRock equal rock? (false): " + superHealRock.equals(healRock));
}
}