Skip to content

Instantly share code, notes, and snippets.

@maragh
Forked from schifano/java-warmup1.java
Created March 9, 2021 19:52
Show Gist options
  • Select an option

  • Save maragh/0930c39abc57510879d57f557482eb2c to your computer and use it in GitHub Desktop.

Select an option

Save maragh/0930c39abc57510879d57f557482eb2c to your computer and use it in GitHub Desktop.
My solutions for CodingBat Java Warmup-1. This is used to document my initial attempts and improved attempts.
/* The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it * is not a weekday or we're on vacation. Return true if we sleep in.
*
* sleepIn(false, false) → true
* sleepIn(true, false) → false
* sleepIn(false, true) → true
*/
public boolean sleepIn(boolean weekday, boolean vacation) {
if (!weekday || vacation) {
return true;
}
return false;
}
/* We have two monkeys, a and b, and the parameters aSmile and bSmile indicate if each is smiling. We are in trouble if they are both smiling or if neither of them is smiling. Return true if we are in trouble.
*
* monkeyTrouble(true, true) → true
* monkeyTrouble(false, false) → true
* monkeyTrouble(true, false) → false
*/
public boolean monkeyTrouble(boolean aSmile, boolean bSmile) {
return (aSmile == bSmile);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment