Re-write following if-else-if statements as Switch statement. Your final code should result in the same output...

70.2K

Verified Solution

Question

Programming

Re-write following if-else-if statements as Switch statement.Your final code should result in the same output as the originalcode below.

if (selection == 10)

System.out.println(\"You selected 10.\");

else if (selection == 20)

System.out.println(\"You selected 20.\");

else if (selection == 30)

System.out.println(\"You selected 30.\");

else if (selection == 40)

System.out.println(\"You selected 40.\");

else System.out.println(\"Not good with numbers, eh?\");

2.

Write a Constructor for the TrafficLight class that setsstopLight value to “red”, waitLight to “yellow” and goLight to“green”?

Answer & Explanation Solved by verified expert
4.2 Ratings (684 Votes)
Hey There I understood your question and I have given the answer to thebest of my knowledge I have also put comments in the code so that you can alsounderstand what I did in the code If you need further explanations then do let me know in thecomments box I will be more than happy to help youAnswerQuestion1 Below I have provided the switch case implementation of thegiven if elseif code While    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students