-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRecipe.java
More file actions
205 lines (141 loc) · 4.88 KB
/
Recipe.java
File metadata and controls
205 lines (141 loc) · 4.88 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
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
201
202
203
204
205
package RecipeBox;
import java.util.Scanner;
import java.util.ArrayList;
/**
*
* @author josh
*/
public class Recipe {
String recipeName;
private int servings;
private ArrayList<Ingredient> recipeIngredients = new ArrayList();
private ArrayList<String> recipeInstructions;
/**
*
* @param recipeName
*/
public void setRecipeName(String recipeName) {
this.recipeName = recipeName;
}
/**
*
* @return
*/
public String getRecipeName() {
return recipeName;
}
/**
*
* @param servings
*/
public void setServings(int servings) {
this.servings = servings;
}
/**
*
* @return
*/
public int getServings() {
return servings;
}
/**
*
* @param recipeIngredients
*/
public void setRecipeIngredients(ArrayList<Ingredient> recipeIngredients) {
this.recipeIngredients = recipeIngredients;
}
/**
*
* @return
*/
public ArrayList<Ingredient> getRecipeIngredients() {
return recipeIngredients;
}
/**
*
* @param recipeInstructions
*/
public void setRecipeInstructions(ArrayList<String> recipeInstructions) {
this.recipeInstructions = recipeInstructions;
}
/**
*
* @return
*/
public ArrayList<String> getRecipeInstructions() {
return recipeInstructions;
}
//Initial Constructor (creates new object with initialized fields)
public Recipe() {
this.recipeName = "";
this.servings = 0;
this.recipeIngredients = new ArrayList<>();
this.recipeInstructions = new ArrayList<>();
}
//Overloaded Constructor
public Recipe(String recipeName, int servings,
ArrayList<Ingredient> recipeIngredients, ArrayList<String> recipeInstructions) {
this.recipeName = recipeName;
this.servings = servings;
this.recipeIngredients = recipeIngredients;
this.recipeInstructions = recipeInstructions;
}
//Add Instructions Method [CUSTOM METHOD]
public void addInstructions() {
String instruction = "";
boolean addMoreInstructions = true;
Scanner scnr = new Scanner(System.in);
do {
System.out.println("Please enter an instruction or type 'end' if you are finished entering instructions: ");
instruction = scnr.nextLine();
if (instruction.toLowerCase().equals("end")) {
addMoreInstructions = false;
}
else {
recipeInstructions.add(instruction);
addMoreInstructions = true;
}
} while (addMoreInstructions == true);
}
//Print Recipe Method
public void printRecipe() {
System.out.println("Recipe: " + recipeName);
System.out.println("Serves: " + servings);
System.out.println("Ingredients: ");
for (int i = 0; i < recipeIngredients.size(); i++) { //For loop to print each array member
recipeIngredients.get(i);
System.out.println(i);
}
System.out.println("Instructions: ");
for (int j = 0; j < recipeInstructions.size(); j++) {
String instruction = recipeInstructions.get(j);
System.out.println(j + instruction);
}
}
//Create New Recipe Method to Build Recipes Based on User Input
public Recipe addNewRecipe() {
ArrayList <Ingredient> recipeIngredients = new ArrayList();
boolean addMoreIngredients = true;
Scanner scnr = new Scanner(System.in);
System.out.println("Please enter the recipe name: ");
String recipeName = scnr.nextLine();
System.out.println("Please enter the number of servings: ");
int servings = scnr.nextInt();
//Do-While loop to add more ingredients (similar to Stepping Stone 4).
do {
System.out.println("Please enter the ingredient name or type 'end' if you are finished entering ingredients: ");
String input = scnr.nextLine();
if (!input.toLowerCase().equals("end")) {
addMoreIngredients = true;
}
else {
addMoreIngredients = false;
break;
}
} while (addMoreIngredients == true);
Recipe recipe1 = new Recipe(recipeName, servings, recipeIngredients, recipeInstructions);
recipe1.printRecipe();
return recipe1;
}
}