-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFood.java
More file actions
47 lines (44 loc) · 1.39 KB
/
Food.java
File metadata and controls
47 lines (44 loc) · 1.39 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
package module5.datastructures.stackqueue;
/**
* Represents an item of food, the number of calories per serving and the number of servings per container
* @author Mae Morella
*/
public class Food implements Cloneable {
final private String name;
final private int calories;
final private int servings;
/**
* Initialize a new Food object
* @param name The name of the food
* @param calories The number of calories per serving
* @param servings The number of servings per container
*/
public Food(String name, int calories, int servings) {
this.name = name;
this.calories = calories;
this.servings = servings;
}
/** @return The name of the food */
public String getName() {
return this.name;
}
/** @return The number of calories per serving */
public int getCaloriesPerServing() {
return this.calories;
}
/** @return The number of servings per container */
public int getServings() {
return this.servings;
}
/** @return the total number of calories per container */
public int getTotalCalories() {
return calories * servings;
}
@Override
public String toString() {
return String.format("%s - %s calories per serving (%s servings)", name, calories, servings);
}
public Food clone() {
return new Food(name, calories, servings);
}
}