Question

In: Computer Science

Write a switch statement that uses the colour of a swab sample of COVID testing vehicle...

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”

Solutions

Expert Solution

Hi,

I am done this with the Javascript. You can find out the below code and you can use the swith logic in any language. Just need to modify the Control which need to modify.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script>
        $(document).ready(function () {
            //This function will execute when HTML dom elements loaded in the Browser
            var btn = $("#btnSendMessage").off("click").on("click", function () {
                //Button Click Events
                CallSwitchStatement();
            })

            //This function will execute when HTML dom elements loaded in the Browser
            var btn = $("#btnClearMessage").off("click").on("click", function () {
                //Button Click Events

                //Clear the Text Value
                $("#txtColor").val("");

                //Call the switch statement
                CallSwitchStatement();
            })

            //Switch Statement
            function CallSwitchStatement() {
                //Get the Messate which need to send
                //we have set message in lower cases and accordingly we have set it to the switch statement
                var Message = $("#txtColor").val().trim().toLowerCase();

                //Switch statement on Message
                switch (Message) {
                    //No Virus Case
                    case "no virus":
                        $($("#txtColor")[0]).css("color", "blue");
                        break;
                    //needs to be under observation Case
                    case "needs to be under observation":
                        $($("#txtColor")[0]).css("color", "Yellow");
                        break;
                    //needs to be admitted in covid ward Case
                    case "needs to be admitted in covid ward":
                        $($("#txtColor")[0]).css("color", "Red");
                        break;
                    //Default Case
                    default:
                        $($("#txtColor")[0]).css("color", "Black");
                }
            }

        });
    </script>
</head>
<body>
    <input type="text" id="txtColor" style="width:400px;height:20px" />
    <input type="button" id="btnSendMessage" value="Check Message Color" style="width:200px;height:20px" />
    <input type="button" id="btnClearMessage" value="Clear Message Color" style="width:200px;height:20px" />
</body>
</html>

Output:

When this HTML loaded in browser and when you entered the cases as below

1) No Virus/no virus/No virus

Chech result after Click the button - Check Message Color

Chech result after Click the button - Clear Message Color

2) Needs to be under Observation/needs to be under observation

Chech result after Click the button - Check Message Color

Chech result after Click the button - Clear Message Color

2) Needs to be admitted in COVID ward/needs to be admitted in covid ward

Chech result after Click the button - Check Message Color

Chech result after Click the button - Clear Message Color


Related Solutions

Write a switch statement that uses the colour of a swab sample of COVID testing vehicle...
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”
Write a switch statement that uses the colour of a swab sample of COVID testing vehicle...
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”
In the main(), below, write a program that uses a switch-statement to choose between three numbers....
In the main(), below, write a program that uses a switch-statement to choose between three numbers. The number, choice, should be prompted for and each choice should print out a unique statement. Also, the prompt should continue indefinitely (i.e. keep prompting until the user force-quits the program), and there should be a general catch-all if the user enters other than the three possible choices. #include <iostream> #include <iomanip> using namespace std; int main() { <your answer goes here> return 0;...
Use a switch statement to write a function that returns TRUE if a character is a...
Use a switch statement to write a function that returns TRUE if a character is a consonant and returns FALSE otherwise.
In a sample of 5000 people, 2% of the population have COVID. In testing, there is...
In a sample of 5000 people, 2% of the population have COVID. In testing, there is a false positive rate of 1.6% and a false negative rate of 4%. a. Compile the results in a chart or a tree diagram. b. In this sample, how many people have COVID? c. What percent of the population have a positive test for COVID? d. What is the probability that a patient has COVID given a positive test? e. What is the probability...
Write a program using switch statement that asks user to enter the month number and then...
Write a program using switch statement that asks user to enter the month number and then it prints out the number of days for that month. For simplicity reasons have your program print 28 days for February no matter if it is a leap year or not. Your program should also handle any invalid month numbers that user could enter (hint use default for the switch). Use a while loop to allow user to test for different month entries till...
Write a program using the switch statement to calculate geometric quantities. Prompt the user to enter...
Write a program using the switch statement to calculate geometric quantities. Prompt the user to enter a radius. Then present a menu of choices for quantities to be calculated from that radius:                         A         Area of a Circle                         C         Circumference of a Circle                         S          Surface Area of a Sphere                         V         Volume of a Sphere Prompt the user to enter the character corresponding to the quantity to be calculated. Use a switch statement to handle the calculations. Use...
With C code Write a switch statement (not a complete program) which prints an appropriate message...
With C code Write a switch statement (not a complete program) which prints an appropriate message for a letter code entered. Use the following messages: If L is entered, output the message "Lakers" If C is entered, output the message "Clippers" If W is entered, output the message "Warriors" If any other character is entered, output the message "invalid code" Make sure to handle the case where the user enters in a small letter. That is, a capital or small...
Discuss the common uses and applications of three or more sample hypothesis testing.
Discuss the common uses and applications of three or more sample hypothesis testing.
Using c# , Write a program using a switch statement that takes one character value from...
Using c# , Write a program using a switch statement that takes one character value from the user and checks whether the entered value is an arithmetic operator (+, -, * , /) If not the program display a message that it not of the operators ( (+, -, * , /) .
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT