-
Notifications
You must be signed in to change notification settings - Fork 0
/
Food.java
101 lines (88 loc) · 2.66 KB
/
Food.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
/*
Class Name: Food
Author: King Lai, ZiCheng Huang, John Oh, Nancy Hao
Date: January 10, 2019
School: A.Y. Jackson Secondary School
Purpose: This class defines food, and initializes the field that composes a food item
*/
public class Food
{
//Encapsulation
private String foodName;
private String ingredient;
private String foodCategory;
private double price;
private int calories;
private String description;
private int availability;
private double costToMake;
//Constructor
public Food (String foodName, String ingredient, String foodCategory, double price, int calories, String description, int availability, double costToMake)
{
this.foodName = foodName;
this.ingredient = ingredient;
this.foodCategory = foodCategory;
this.price = price;
this.calories = calories;
this.description = description;
this.availability = availability;
this.costToMake = costToMake;
}
//Accessors and Mutators
//Encapsulation
public String getFoodName() {
return foodName;
}
public String getIngredient() {
return ingredient;
}
public int getCalories() {
return calories;
}
public String getDescription() {
return description;
}
public double getPrice() {
return price;
}
public int getAvailability() {
return availability;
}
public String getFoodCategory ()
{
return foodCategory;
}
public double getCostToMake () {
return costToMake;
}
public void setAvailability (int availability) {
this.availability = availability;
}
/*
Parameters:
- amount: The number of items that the food needs to be changed to.
Return Value: This method does not return anything because it is a void
Purpose: To set the availability based on the number of food items left after it has been added to order
*/
public void changeAvailability (int amount) {
if (amount < 0) {
System.out.println ("You have entered an amount greater than the availability.\nChanging availability to 0.");
this.availability = 0;
} else {
this.availability = amount;
}
}
/*
Return Value: This method returns a String value.
Purpose: To show the food information in a written form.
*/
public String toString ()
{
return "Name: " + foodName + "\n" +
"Ingredient: " + ingredient + "\n" +
"Category: " + foodCategory + "\n" +
"Price: $" + price + "\n" +
"Calories: " + calories + "\n" +
"Description: " + description + "\n";
}
}