-
Notifications
You must be signed in to change notification settings - Fork 2
/
Item.java~
105 lines (91 loc) · 2.63 KB
/
Item.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Item.java
* @author Emma Shumadine, Lily Orth-Smith, Rachel Zhang
* */
public class Item {
protected String name;
protected String description;
/**
* Creates an item
* @param n the name of the item
* @param d the description
*/
public Item(String n, String d) {
name = n;
description = d;
}
/**
* Returns the name of the item
* @return the name of the item
*/
public String getName() {
return name;
}
/**
* Returns the item's description
* @return the description
*/
public String getDescription() {
return description;
}
/**
* Sets the name of the item
* @param n the item's name
*/
public void setName(String n) {
name = n;
}
/**
* Sets the item's description
* @param d the description
*/
public void setDescription(String d){
description = d;
}
/**
* Returns true if the items have the same name and same description
* @param otherItem the item to be compared
* @return true if the items have the same name and the same description
*/
public boolean equals(Item otherItem) {
boolean sameName = name.equals(otherItem.getName());
boolean sameDescription = description.equals(otherItem.getDescription());
return (sameName && sameDescription);
}
/**
* Returns a new item with the same name and description
* @return a cloned item
*/
public Item clone() {
return new Item(name, description);
}
/**
* Returns the HP of the item (0 if it is not a HealItem)
* @return the HP of the item
*/
public int getHp() {
return 0;
}
/**
* Returns a string representation of the item
* @return a string representation of the item
*/
public String toString() {
return name + ": " + description;
}
public static void main(String[] args) {
Item rock = new Item("Rock", "Does nothing.");
Item rock2 = new Item("Rock", "Does nothing.");
System.out.println("rock: " + rock);
System.out.println("rock2: " + rock2);
System.out.println("Does rock equal rock2? (true): " + rock.equals(rock2));
System.out.println("Testing rock.getName()-->" + rock.getName());
System.out.println("Testing rock.getDescription()-->" + rock.getDescription());
System.out.println("Setting rock name to 'Pebble'");
rock.setName("Pebble");
System.out.println("Setting rock description to 'Can be thrown.'");
rock.setDescription("Can be thrown.");
System.out.println(rock);
System.out.println("Does rock equal rock2? (false): " + rock.equals(rock2));
}
}