Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oliwia Kepczynska #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 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,104 @@ 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 sayGoodMorning(false);
}

// 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 sayGoodMorning(true);
}

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

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

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

// 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;
if (nums.length != 0) {
return true;
} else {
return false;
}
}

// 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;
if (sentence.contains("milk")) {
return true;
} else {
return false;
}
}

// 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;
if (sentence.contains("milk") && (sentence.contains("coffee"))) {
return 9;
} else if (sentence.contains("milk")) {
return 3;
} else if (sentence.contains("coffee")) {
return 6;
}
return 0;
}


// 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;
if (num >= lower && num <= upper) {
return true;
} else {
return false;
}
}

/*
Expand All @@ -123,6 +153,17 @@ 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 >= 1 && age <= 4) {
return "Toddler";
} else if (age >= 5 && age <= 12) {
return "Child";
} else if (age >= 13 && age <= 19) {
return "Teenager";
} else {
return "Adult";
}
}
}
30 changes: 26 additions & 4 deletions src/main/java/com/booleanuk/extension/Extension.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ public class Extension extends ExtensionBase {
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 >= 1) {
return "The cake is still baking!";
} else {
return "The timer finished ages ago!";
}
}



Expand All @@ -27,7 +36,13 @@ 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 time) {
if (time == 0) {
return ingredients.length * 2;
} else {
return ingredients.length * time;
}
}

/* 3.
Create a method named calculateGramsOfSugar that accepts two parameters:
Expand All @@ -41,7 +56,14 @@ 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) {
int grams = 0;
for (String ing : ingredients){
if (ing.equals("sugar")){
grams+=100*layers;
break;
}
}
return grams;
}
}