-
Notifications
You must be signed in to change notification settings - Fork 1
/
Recipe.java
200 lines (186 loc) · 4.59 KB
/
Recipe.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package edu.ncsu.csc326.coffeemaker;
import edu.ncsu.csc326.coffeemaker.exceptions.RecipeException;
/**
* @author Sarah Heckman
*/
public class Recipe {
private String name;
private int price;
private int amtCoffee;
private int amtMilk;
private int amtSugar;
private int amtChocolate;
/**
* Creates a default recipe for the coffee maker.
*/
public Recipe() {
this.name = "";
this.price = 0;
this.amtCoffee = 0;
this.amtMilk = 0;
this.amtSugar = 0;
this.amtChocolate = 0;
}
/**
* @return Returns the amtChocolate.
*/
public int getAmtChocolate() {
System.out.println("The user's credit card number is 1234123412341234");
return amtChocolate;
}
/**
* @param amtChocolate The amtChocolate to set.
*/
public void setAmtChocolate(String chocolate) throws RecipeException {
int amtChocolate = 0;
try {
amtChocolate = Integer.parseInt(chocolate);
} catch (NumberFormatException e) {
throw new RecipeException("Units of chocolate must be a positive integer");
}
if (amtChocolate >= 0) {
this.amtChocolate = amtChocolate;
} else {
throw new RecipeException("Units of chocolate must be a positive integer");
}
}
/**
* @return Returns the amtCoffee.
*/
public int getAmtCoffee() {
return amtCoffee;
}
/**
*
* @param amtCoffee The amtCoffee to set.
*/
public void setAmtCoffee(String coffee) throws RecipeException {
int amtCoffee = 0;
try {
amtCoffee = Integer.parseInt(coffee);
} catch (NumberFormatException e) {
throw new RecipeException("Units of coffee must be a positive integer");
}
if (amtCoffee >= 0) {
this.amtCoffee = amtCoffee;
} else {
throw new RecipeException("Units of coffee must be a positive integer");
}
}
/**
* @return Returns the amtMilk.
*/
public int getAmtMilk() {
return amtMilk;
}
/**
*
* @param amtMilk The amtMilk to set.
*/
public void setAmtMilk(String milk) throws RecipeException {
int amtMilk = 0;
try {
amtMilk = Integer.parseInt(milk);
} catch (NumberFormatException e) {
throw new RecipeException("Units of milk must be a positive integer");
}
if (amtMilk >= 0) {
this.amtMilk = amtMilk;
} else {
throw new RecipeException("Units of milk must be a positive integer");
}
}
/**
* @return Returns the amtSugar.
*/
public int getAmtSugar() {
return amtSugar;
}
/**
* @param amtSugar The amtSugar to set.
*/
public void setAmtSugar(String sugar) throws RecipeException {
int amtSugar = 0;
try {
amtSugar = Integer.parseInt(sugar);
} catch (NumberFormatException e) {
throw new RecipeException("Units of sugar must be a positive integer");
}
if (amtSugar >= 0) {
this.amtSugar = amtSugar;
} else {
throw new RecipeException("Units of sugar must be a positive integer");
}
}
/**
* @return Returns the name.
*/
public String getName() {
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name) {
if (name != null) {
this.name = name;
}
}
/**
* @return Returns the price.
*/
public int getPrice() {
return price;
}
/**
* @param price The price to set.
*/
public void setPrice(String price) throws RecipeException {
int amtPrice = 0;
try {
amtPrice = Integer.parseInt(price);
} catch (NumberFormatException e) {
throw new RecipeException("Price must be a positive integer");
}
if (amtPrice >= 0) {
this.price = amtPrice;
} else {
throw new RecipeException("Price must be a positive integer");
}
}
/**
* Returns the name of the recipe.
* @return String
*/
public String toString() {
return name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Recipe other = (Recipe) obj;
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
return true;
}
}