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.
The switch statement allows us to execute a block of code among many alternatives
syntax
switch (expression) {
case constant1:
// code to be executed if
// expression is equal to constant1;
break;
case constant2:
// code to be executed if
// expression is equal to constant2;
break;
.
.
.
default:
// code to be executed if
// expression doesn't match any constant
}
code:
String color ="user defined color";
switch(color){
case blue:
System.out.println("no virus");
break;
case yellow:
System.out.println("N to be under observation");
break;
case red:
System.out.println("Need top be admitted in the covid ward");
break;
}
here the switch statement will take the color and display the message the corresponding message to the local doctor.
please
upvote if find useful.
Get Answers For Free
Most questions answered within 1 hours.