-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRecipe.java
82 lines (65 loc) · 1.86 KB
/
Recipe.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
package recipeBook;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
public class Recipe{
// Name of recipe as a string
private String name;
// Ingredients stored in an arraylist of strings
private List<String> ingredientsList;
// store instructions as a long string separated by new line
private String instructionList;
// default constructor
public Recipe() {
this.name = "";
this.ingredientsList = new ArrayList<String>();
this.instructionList = "";
}
// constructor for recipe
public Recipe(String name, String[] ingredientsList, String instructionList) {
this.name = name;
this.ingredientsList = Arrays.asList(ingredientsList);
this.instructionList = instructionList;
}
// getter for name
public String getName() {
return this.name;
}
// setter for name
public void setName(String name) {
this.name = name;
}
// getter for ingredientsList
public List<String> getIngredientsList() {
return ingredientsList;
}
public String getIngredientsString() {
String result = "";
for (String ingredient : this.ingredientsList) {
result = result + ingredient + ", ";
}
return result;
}
// setter for ingredientsList
public void setIngredientsList(String[] ingredientsList) {
this.ingredientsList.clear();
for (int i = 0; i < ingredientsList.length; i++) {
this.ingredientsList.add(ingredientsList[i]);
}
}
// getter for instructionList
public String getInstructionList() {
return instructionList.strip();
}
// setter for instructionList
public void setInstructionList(String instructionList) {
this.instructionList = instructionList;
}
public String toString() {
String result = "";
result += "NAME: " + this.getName() + "\n";
result += "INGREDIENTS: " + this.getIngredientsList() + "\n";
result += "INSTRUCTIONS:\n" + this.getInstructionList();
return result;
}
}