-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecipe.java
More file actions
87 lines (71 loc) · 2.34 KB
/
Recipe.java
File metadata and controls
87 lines (71 loc) · 2.34 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
import java.util.ArrayList;
import java.util.List;
public class Recipe {
public String title;
public String description;
public List<String> ingredients;
public List<String> instructions;
public Recipe() {
ingredients = new ArrayList<String>();
instructions = new ArrayList<String>();
}
public void settitle(String intitle){
this.title = intitle;
}
public void setdescription(String indescription){
this.description = indescription;
}
public void addingredient (String ingredient){
ingredients.add(ingredient);
}
public void addinstructions (String instruction){
instructions.add(instruction);
}
public String gettitle(){
return title;
}
public String getDescription() {
return description;
}
public String getIngrident(int i) {
return ingredients.get(i);
}
public List<String> getInstructions() {
return instructions;
}
public List<String> getIngridients(){
return ingredients;
}
//for file format
public String toString(){
StringBuffer data = new StringBuffer();
data.append("Title: #" + title + "# \n");
data.append("Description: #" + description + "# \n");
data.append("Ingredeint: #");
for (String ingredient : ingredients){
data.append(ingredient + "\n");
}
data.append("Instructions: #");
for (String instruction : instructions){
data.append(instruction + "\n");
}
return data.toString();
}
//for printing when user wants to see all the recipe at once
public String userToString(){
StringBuffer data = new StringBuffer();
data.append("\nTitle: \n" + title + "\n");
data.append("\nDescription: \n" + description + "\n");
data.append("\nIngredients: \n");
for (int index = 0; index < ingredients.size(); index++){
String ingredient = ingredients.get(index);
data.append((index+1) + ". " + ingredient + "\n");
}
data.append("\nInstructions: \n");
for (int index = 0; index < instructions.size(); index++){
String instruction = instructions.get(index);
data.append((index+1) + ". " + instruction + "\n");
}
return data.toString();
}
}