Skip to content

Commit

Permalink
Completed core and extension. Passed all tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Svennas committed Jan 10, 2024
1 parent 03c6052 commit 72f5b06
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
36 changes: 23 additions & 13 deletions src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,74 +40,80 @@ public String sayGoodMorning(boolean isMorning) {
// 1. What will the returned value be if I run sayGoodMorning(false)?
// Change the returned value in the method below to your answer. It is case-sensitive.
public String one() {
return "";
return "Good day!";
}

// 2. What will the output be if I run sayGoodMorning(true)?
// Change the returned value in the method below to your answer. It is case-sensitive.
public String two() {
return "";
return "Good morning!";
}

// 3. What will the output be if I run sayGoodMorning("Hello".equals("Hello"))?
// Change the returned value in the method below to your answer. It is case-sensitive.
public String three() {
return "";
return "Good morning!";
}

// 4. What will the output be if I run sayGoodMorning(!"A word".equals("Another word"))
public String four() {
return "";
return "Good morning!";
}

// 5. What will the output be if I run sayGoodMorning(25 != 25)
public String five() {
return "";
return "Good day!";
}

// 6. Use a conditional statement to return "Correct!" if the input is more than 7
// or "Wrong!" if not
public String six(int num) {
return "Not implemented yet!";
if (num > 7) return "Correct!";
else return "Wrong!";
}

// 7. Use a conditional statement to return "Correct!" if the input is false
// or "Wrong!" if not
public String seven(boolean bool) {
return "Not implemented yet!";
if (!bool) return "Correct!";
else return "Wrong!";
}

// 8. Use a conditional statement to return "Correct!" if numOne is more than or equal to numTwo
// or "Wrong!" if not
public String eight(int numOne, int numTwo) {
return "Not implemented yet!";
if (numOne >= numTwo) return "Correct!";
else return "Wrong!";
}

// 9. Use a conditional statement to return true if the array provided is not empty
// or false if it is empty
public boolean nine(int[] nums) {
return false;
return (nums.length != 0);
}

// 10. Use a conditional statement to return true if the provided string contains the word
// "milk", or false if not
// https://www.w3schools.com/java/java_ref_string.asp
public boolean ten(String sentence) {
return false;
return (sentence.contains("milk"));
}

// 11. Use conditional statements to return the number 3 if the provided string contains
// the word milk. Return the number 6 if the provided string contains the word coffee.
// Return the number 9 if the string contains both coffee and milk.
// Otherwise, return the number 0.
public int eleven(String sentence) {
return -1;
int total = 0;
if (sentence.contains("milk")) total += 3;
if (sentence.contains("coffee")) total += 6;
return total;
}

// 12. Use conditional statements to return true if num is more than or equal to lower and is
// less than or equal to upper, otherwise return false.
public boolean twelve(int num, int lower, int upper) {
return false;
return (num >= lower && num <= upper);
}

/*
Expand All @@ -123,6 +129,10 @@ public boolean twelve(int num, int lower, int upper) {
20+ | Adult
*/
public String thirteen(int age) {
return "Not implemented yet!";
if (age == 0) return "Baby";
else if (age <= 4) return "Toddler";
else if (age <= 12) return "Child";
else if (age <= 19) return "Teenager";
else return "Adult";
}
}
26 changes: 20 additions & 6 deletions src/main/java/com/booleanuk/extension/Extension.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ public class Extension extends ExtensionBase {
and "The timer finished ages ago!" if the remaining minutes is a negative number
*/



public String timerStatus(int remaining) {
if (remaining == 0) return "The cake is ready!";
else if (remaining > 0) return "The cake is still baking!";
return "The timer finished ages ago!";
}

/* 2.
Create a method named estimatePrepTime that accepts two parameters:
Expand All @@ -27,7 +30,10 @@ public class Extension extends ExtensionBase {
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 times) {
if (times == 0) times = 2;
return ingredients.length * times;
}

/* 3.
Create a method named calculateGramsOfSugar that accepts two parameters:
Expand All @@ -41,7 +47,15 @@ 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 layers) {
boolean sugar = false;
for (int i = 0; i < ingredients.length; i++) {
if (ingredients[i] == "sugar") {
sugar = true;
break;
}
}
if (!sugar) return 0;
return layers * 100;
}
}

0 comments on commit 72f5b06

Please sign in to comment.