Skip to content

Commit

Permalink
extension exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
Alicja Bobko committed Jul 5, 2023
1 parent db43e00 commit 1f1807d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/main/java/com/booleanuk/extension/Extension.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.booleanuk.helpers.ExtensionBase;

import java.util.Arrays;

public class Extension extends ExtensionBase {
/* 1.
We're going to improve our cake baking capabilities!
Expand All @@ -15,8 +17,12 @@ public class Extension extends ExtensionBase {
*/


public String timerStatus(int remaining) {
if (remaining > 0) return "The cake is still baking!";
else if (remaining == 0) return "The cake is ready!";
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"]
Expand All @@ -26,6 +32,10 @@ public class Extension extends ExtensionBase {
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 prepTime ) {
if (prepTime == 0) prepTime = 2;
return ingredients.length * prepTime;
}



Expand All @@ -40,6 +50,19 @@ public class Extension extends ExtensionBase {
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 numOfLayers) {
int gramsOfSugarPerLayer = 100;
int totalGramsOfSugar = 0;

for (String ingredient : ingredients) {
if (ingredient.equals("sugar")) {
totalGramsOfSugar += gramsOfSugarPerLayer * numOfLayers;
break;
}
}

return totalGramsOfSugar;
}



Expand Down

0 comments on commit 1f1807d

Please sign in to comment.