Write a switch statement that uses the colour of a swab sample of COVID testing vehicle to send a message to a local doctor. Use the messages given for each colour in the table below. Justify your answer.
Colour |
Message |
Blue |
“No virus” |
Yellow |
“Needs to be under observation” |
Red |
“Needs to be admitted in COVID ward” |
// Assuming that color is a string which already is declared and assigned a string value switch (color) { // switch on color case "Blue": // if the color is Blue System.out.println("No virus"); // print "No virus" break; case "Yellow": // if the color is Yellow System.out.println("Needs to be under observation"); break; case "Red": // if the color is Red System.out.println("Needs to be admitted in COVID ward"); break; }
Get Answers For Free
Most questions answered within 1 hours.