-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFood.java
More file actions
162 lines (138 loc) · 3.17 KB
/
Food.java
File metadata and controls
162 lines (138 loc) · 3.17 KB
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
/*
* @authour: muteeba jamal <a href="mailto:muteeba.jamal@ucalgary.ca">
* muteeba.jamal@ucalgary.ca</a>
* @authour: shahzill naveed <a href="mailto:shahzill.naveed@ucalgary.ca">
* shahzill.naveed@ucalgary.ca</a>
* @authour: ahsan zia <a href="mailto:ahsan.zia@ucalgary.ca">
* ahsan.zia@ucalgary.ca</a>
* @authour: hridika banik <a href="mailto:hridika.banik@ucalgary.ca">
* hridika.banik@ucalgary.ca</a>
* @version 1.4
* @since 1.0
*/
package edu.ucalgary.ensf409;
import java.util.LinkedList;
public class Food {
int itemID;
String name;
int grainC;
int fruitVegC;
int proteinC;
int otherC;
int calorie;
/*
* Food Constructor
*
* Constructs a Food object with the data of a particular food.
*
* @param String itemID
* @param String name
* @param String grainC
* @param String fruitVegC
* @param String proteinC
* @param String otherC
* @param String calorie
*
* IllegalArgumentException is thrown if invalid data is provided.
*/
public Food(String itemID, String name, String grainC, String fruitVegC, String proteinC, String otherC, String calorie){
if(Integer.parseInt(itemID) >= 0 && Integer.parseInt(grainC) >= 0 && Integer.parseInt(fruitVegC) >= 0 &&
Integer.parseInt(proteinC) >= 0 && Integer.parseInt(otherC) >= 0 && Integer.parseInt(calorie) >= 0){
this.itemID = Integer.parseInt(itemID);
this.name = name;
this.grainC = Integer.parseInt(grainC);
this.fruitVegC = Integer.parseInt(fruitVegC);
this.proteinC = Integer.parseInt(proteinC);
this.otherC = Integer.parseInt(otherC);
this.calorie = Integer.parseInt(calorie);
}
else{
throw new IllegalArgumentException();
}
}
/*
* Setter methods.
*
* These methods are used to set/change content details of a food.
*
* The argument is the new value we would like to set.
*
* IllegalArgumentException is thrown if invalid data is provided.
*/
// @param int g
public void setGrainC(int g){
if(g >= 0){
grainC = g;
}
else{
throw new IllegalArgumentException();
}
}
// @param int fV
public void setFruitVegC(int fV){
if(fV >= 0){
fruitVegC = fV;
}
else{
throw new IllegalArgumentException();
}
}
// @param int p
public void setProtenC(int p){
if(p >= 0){
proteinC = p;
}
else{
throw new IllegalArgumentException();
}
}
// @param int o
public void setOtherC(int o){
if(o >= 0){
otherC = o;
}
else{
throw new IllegalArgumentException();
}
}
// @param int c
public void setCalorie(int c){
if(c >= 0){
calorie = c;
}
else{
throw new IllegalArgumentException();
}
}
/*
* Getter methods.
*
* These methods are used to get data for a food object.
*/
public String getName(){
return name;
}
public int getFoodID(){
return itemID;
}
public int getGrainC(){
return grainC;
}
public int getFruitVegC(){
return fruitVegC;
}
public int getProteinC(){
return proteinC;
}
public int getOtherC(){
return otherC;
}
public int getCalorie(){
return calorie;
}
// getTotalCalorie() calculated the total calorie contant of a food.
public int getTotalCalorie(){
int total = grainC+fruitVegC+proteinC+otherC+calorie;
return total;
}
}