Skip to content

Commit

Permalink
switch challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
bowbahdoe committed Sep 30, 2024
1 parent f202ada commit 27660a4
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion src/switch/challenges.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,60 @@ void main() {
}
```

## Challenge 4.
## Challenge 5.

Given a type of bear, return the correct course of action
if you run into one in the wild and it attacks you.

If the bear is `null`, return `null` as the action to take.

If you don't know what to do when you run into a bear, look it up. Use `switch`
first then try writing the same logic using `if` and `else`.

```java
enum Bear {
POLAR,
BROWN,
BLACK,
PANDA,
KOALA
}

enum Action {
LAY_DOWN,
FIGHT_BACK,
RUN_AWAY
YEET
}

Action inCaseOfBearAttack(Bear bear) {
// CODE HERE
}

void main() {
System.out.println(
inCaseOfBearAttack(Bear.POLAR)
);

System.out.println(
inCaseOfBearAttack(Bear.BROWN)
);


System.out.println(
inCaseOfBearAttack(Bear.BLACK)
);

System.out.println(
inCaseOfBearAttack(Bear.PANDA)
);

System.out.println(
inCaseOfBearAttack(Bear.KOALA)
);

System.out.println(
inCaseOfBearAttack(null)
);
}
```

0 comments on commit 27660a4

Please sign in to comment.