File tree Expand file tree Collapse file tree 1 file changed +57
-1
lines changed
Expand file tree Collapse file tree 1 file changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -158,4 +158,60 @@ void main() {
158158}
159159```
160160
161- ## Challenge 4.
161+ ## Challenge 5.
162+
163+ Given a type of bear, return the correct course of action
164+ if you run into one in the wild and it attacks you.
165+
166+ If the bear is ` null ` , return ` null ` as the action to take.
167+
168+ If you don't know what to do when you run into a bear, look it up. Use ` switch `
169+ first then try writing the same logic using ` if ` and ` else ` .
170+
171+ ``` java
172+ enum Bear {
173+ POLAR ,
174+ BROWN ,
175+ BLACK ,
176+ PANDA ,
177+ KOALA
178+ }
179+
180+ enum Action {
181+ LAY_DOWN ,
182+ FIGHT_BACK ,
183+ RUN_AWAY
184+ YEET
185+ }
186+
187+ Action inCaseOfBearAttack(Bear bear) {
188+ // CODE HERE
189+ }
190+
191+ void main() {
192+ System . out. println(
193+ inCaseOfBearAttack(Bear . POLAR )
194+ );
195+
196+ System . out. println(
197+ inCaseOfBearAttack(Bear . BROWN )
198+ );
199+
200+
201+ System . out. println(
202+ inCaseOfBearAttack(Bear . BLACK )
203+ );
204+
205+ System . out. println(
206+ inCaseOfBearAttack(Bear . PANDA )
207+ );
208+
209+ System . out. println(
210+ inCaseOfBearAttack(Bear . KOALA )
211+ );
212+
213+ System . out. println(
214+ inCaseOfBearAttack(null )
215+ );
216+ }
217+ ```
You can’t perform that action at this time.
0 commit comments