-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathExtension.java
More file actions
68 lines (54 loc) · 2.38 KB
/
Extension.java
File metadata and controls
68 lines (54 loc) · 2.38 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
package com.booleanuk.extension;
import com.booleanuk.helpers.ExtensionBase;
public class Extension extends ExtensionBase {
/* 1.
We're going to improve our cake baking capabilities!
Create a public method named timerStatus that accepts one parameter:
- the number of minutes left on the timer
The method must return "The cake is ready!" if the remaining minutes is 0,
"The cake is still baking!" if there are any remaining minutes left,
and "The timer finished ages ago!" if the remaining minutes is a negative number
*/
public String timerStatus(int minutes){
if(minutes == 0){
return "The cake is ready!";
} else if(minutes > 0) {
return "The cake is still baking!";
} else{
return "The timer finished ages ago!";
}
}
/* 2.
Create a method named estimatePrepTime that accepts two parameters:
- an array of ingredients, e.g. ["sugar", "milk", "flour", "eggs"]
- the prep time per ingredient in minutes
The method must return the total prep time required based on the number of ingredients
provided and the prep time per ingredient.
If a prep time of 0 is provided, the method should assume each ingredient takes 2 minutes to prepare.
*/
public int estimatePrepTime(String[] ingredients, int time) {
int preptime = time;
if (preptime == 0) {
preptime = 2;
}
return ingredients.length*preptime;
}
/* 3.
Create a method named calculateGramsOfSugar that accepts two parameters:
- an array of ingredients that will always contain 3 ingredients
- the number of layers the cake has
The cake will need 100g of sugar per layer, if that ingredient is present in the provided list of ingredients
and 0g if that ingredient is missing.
The method should return the number of grams of sugar needed to make the cake.
You may need to use programming techniques we have yet to cover in the course to solve this task.
*/
public int calculateGramsOfSugar(String[] ingredients, int layers){
boolean containsSugar = false;
for(int i = 0; i < 3; i++){
if(ingredients[i].equals("sugar")){
containsSugar = true;
}
}
return containsSugar ? 100*layers : 0;
}
}