-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecipe.java
More file actions
250 lines (204 loc) · 8.11 KB
/
Copy pathRecipe.java
File metadata and controls
250 lines (204 loc) · 8.11 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import java.util.Scanner;
import java.util.ArrayList;
import java.io.*;
public class Recipe {
//Fields
private Scanner keyboard;
private String dishName;
private String folderName;
private ArrayList<String> ingredients;
private String ingredientsFile;
private ArrayList<String> instructions;
private String instructionsFile;
private ArrayList<String> modifications;
private String modificationsFile;
//Constructors
public Recipe(String dishName, ArrayList<String> ingredients, ArrayList<String> instructions, ArrayList<String> modifications) throws IOException {
this.dishName = dishName.toLowerCase();
this.folderName = "Recipes/" + this.dishName;
makeFolder("Recipes");
makeFolder(this.folderName);
this.ingredients = ingredients;
this.ingredientsFile = this.folderName + "/ingredients.txt";
this.instructions = instructions;
this.instructionsFile = this.folderName + "/instructions.txt";
this.modifications = modifications;
this.modificationsFile = this.folderName + "/modifications.txt";
}
public Recipe(String dishName, ArrayList<String> ingredients, ArrayList<String> instructions) throws IOException {
this.dishName = dishName;
this.folderName = "Recipes/" + this.dishName;
makeFolder("Recipes");
makeFolder(this.folderName);
this.ingredients = ingredients;
this.ingredientsFile = this.folderName + "/ingredients.txt";
this.instructions = instructions;
this.instructionsFile = this.folderName + "/instructions.txt";
this.modificationsFile = this.folderName + "/modifications.txt";
}
public Recipe(String dishName, ArrayList<String> ingredients) throws IOException {
this.dishName = dishName;
this.folderName = "Recipes/" + this.dishName;
makeFolder("Recipes");
makeFolder(this.folderName);
this.ingredients = ingredients;
this.ingredientsFile = this.folderName + "/ingredients.txt";
this.instructionsFile = this.folderName + "/instructions.txt";
this.modificationsFile = this.folderName + "/modifications.txt";
}
public Recipe(String dishName) throws IOException{
this.dishName = dishName;
this.folderName = "Recipes/" + this.dishName;
makeFolder("Recipes");
makeFolder(this.folderName);
this.ingredientsFile = this.folderName + "/ingredients.txt";
this.instructionsFile = this.folderName + "/instructions.txt";
this.modificationsFile = this.folderName + "/modifications.txt";
}
//Summary (called printRecipe)
public void printRecipe() {
System.out.printf("Dish Name: %s\n", this.dishName);
printIngredients();
printInstructions();
printModifications();
}
public void printRecipeDebug() {
System.out.printf("Dish Name = %s\n", this.dishName);
System.out.printf("Folder Name = %s\n", this.folderName);
printIngredients();
System.out.printf("Ingredients File = %s\n", this.ingredientsFile);
printInstructions();
System.out.printf("Instructions File = %s\n", this.instructionsFile);
printModifications();
System.out.printf("Modifications File = %s\n", this.modificationsFile);
}
//Getters
public String getdishName() {
return this.dishName;
}
public String getfolderName() {
return this.folderName;
}
public ArrayList<String> getingredients() {
return this.ingredients;
}
public String getingredientsFile() {
return this.ingredientsFile;
}
public ArrayList<String> getinstructions() {
return this.instructions;
}
public String getinstructionsFile() {
return this.instructionsFile;
}
public ArrayList<String> getmodifications() {
return this.modifications;
}
public String getmodificationsFile() {
return this.modificationsFile;
}
//Setters
public void setdishName(String dishName) {
this.dishName = dishName;
setfolderName(this.dishName);
}
public void setfolderName(String folderName) {
File folder = new File(this.folderName);
File rename = new File("Recipes/" + folderName);
if (!folder.isDirectory()) {
System.err.println("Current folder is not a folder. Please check class fields.");
return;
}
boolean flag = folder.renameTo(rename);
if (flag == true) {
this.folderName = "Recipes/" + folderName;
System.out.printf("Folder/Recipe name is now %s.\n", this.folderName);
updateingredientsFile();
updateinstructionsFile();
updatemodificationsFile();
}
else {
System.out.println("Rename failed");
}
}
public void setingredients(ArrayList<String> ingredients) {
this.ingredients = ingredients;
}
public void updateingredientsFile() {
this.ingredientsFile = this.folderName + "/ingredients.txt";
}
public void setinstructions(ArrayList<String> instructions) {
this.instructions = instructions;
}
public void updateinstructionsFile() {
this.instructionsFile = this.folderName + "/instructions.txt";
}
public void setmodifications(ArrayList<String> modifications) {
this.modifications = modifications;
}
public void updatemodificationsFile() {
this.modificationsFile = this.folderName + "/modifications.txt";
}
//Other Methods
public void printIngredients() {
System.out.println("Ingredients: ");
int listSize = this.ingredients.size();
if (listSize <= 0) {
System.out.println("Nothing to list.");
return;
}
for (int i = 0; i < listSize; i++) {
System.out.printf("%s\n", this.ingredients.get(i));
}
}
public void printInstructions() {
System.out.println("Instructions: ");
int listSize = this.instructions.size();
if (listSize <= 0) {
System.out.println("Nothing to list.");
return;
}
for (int i = 0; i < listSize; i++) {
System.out.printf("%s\n", this.instructions.get(i));
}
}
public void printModifications() {
System.out.println("Modifications: ");
int listSize = this.modifications.size();
if (listSize <= 0) {
System.out.println("Nothing to list.");
return;
}
for (int i = 0; i < listSize; i++) {
System.out.printf("%s\n", this.modifications.get(i));
}
}
private void makeFolder(String newFolderName) throws IOException {
keyboard = new Scanner(System.in);
File folder = new File(newFolderName).getAbsoluteFile();
if (folder.exists()) {
return;
}
System.out.printf("%s directory not found.\n", newFolderName);
System.out.printf("Respond YES if you would like the program to make a %s directory for you.\n", newFolderName);
System.out.printf("N.B IF A %s FOLDER DOES EXIST IN THIS DIRECTORY, "
+ "IT WILL BE OVERWRITTEN IF YOU RESPOND YES!\n", newFolderName);
System.out.print("Respond here: ");
String response = keyboard.nextLine();
if (!response.equalsIgnoreCase("YES")) {
System.out.printf("Please quit, check your folders, and make a backup of any folder named %s.\n", newFolderName);
System.exit(1);
}
try {
if (folder.mkdir()) {
System.out.println(newFolderName + " directory created.");
}
else {
System.out.println("Failed to create " + newFolderName + " directory.");
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}