-
Notifications
You must be signed in to change notification settings - Fork 1
/
Item.java
93 lines (85 loc) · 1.82 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
/**
* Item object contains short name (to be displayed on button), long name
* (everywhere else) and pricing information. These properties are immutable for
* given Item object
*
* @author Chae Jubb
* @version 1.0
*/
public class Item {
private final String shortName, fullName;
private final double price;
/**
* Constructor
*
* @param shortName
* Name for button
* @param fullName
* Name for other uses
* @param price
* Price of item
*/
public Item(String shortName, String fullName, double price) {
this.shortName = shortName;
this.fullName = fullName;
this.price = price;
}
/**
* Constructor. Allows object to be created using only short name. (Used
* when comparing button to Menu items)
*
* @param shortName
* Name for button
*/
public Item(String shortName) {
this.shortName = shortName;
this.fullName = null;
this.price = 0;
}
/**
* Getter method for short name
*
* @return Short Name
*/
public String getShortName() {
return this.shortName;
}
/**
* Getter method for full name
*
* @return Full Name
*/
public String getFullName() {
return this.fullName;
}
/**
* Getter method for price
*
* @return Price
*/
public double getPrice() {
return this.price;
}
/**
* Concatenates full name with price for String representation
*
* @return full name concatentated with price
*/
public String toString() {
return this.fullName + " " + this.price;
}
/**
* Checks if short names are equal
*
* @param otherItem
* Item to be compared against implicit parameter
* @return true if short names equivalent; false otherwise
*/
public boolean isEqual(Item otherItem) {
if (this.shortName.equals(otherItem.getShortName())) {
return true;
} else {
return false;
}
}
}