Question

(JAVA)writer a switch statement that mimics the following scenario. if traffic light is yellow, slow down....

(JAVA)writer a switch statement that mimics the following scenario. if traffic light is yellow, slow down. if traffic light is green, gooooo. if traffic light is red, stop.....stop. ****the switch statement must evaluate either characters or integers.(PLEASE I NEED FULL CODE)

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class Traffic {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter traffic light color(r, g or b): ");
        char color = in.next().charAt(0);
        switch (color) {
            case 'r':
                System.out.println("slow down");
                break;
            case 'g':
                System.out.println("gooooo");
                break;
            case 'b':
                System.out.println("stop.....stop");
                break;
            default:
                System.out.println("Invalid input..");
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
(JAVA)writer a switch statement that mimics the following scenario. if traffic light is yellow, slow down....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Word Problem) Two two-way streets meet at an intersection controlled by a four-way traffic light. In...

    Word Problem) Two two-way streets meet at an intersection controlled by a four-way traffic light. In the east and west directions, the lights cycle from green to yellow to red. The south-facing lights do the same thing, except that they are red when the east-west lights are green or yellow, and vice versa. However, the north-facing lights are augmented with a green left turn arrow. They cycle red-green arrow-yellow arrow-green-yellow-red. Consider the following additional problem specifications: When the green or...

  • Need some guidance with the following problems as I am new to Java programming. Any assistance...

    Need some guidance with the following problems as I am new to Java programming. Any assistance is greatly appreciated. Thanks Using printf and specifiers for all print instructions: 1.            Code the following: a.            10% is stored in a variable called discount when the customer is a student; otherwise, it stores 0%. Code this if … else control structure using the conditional operator (ternary operator). The variables discount and student have already been declared. Assume student is a boolean variable. b.           ...

  • can someone answer these please!! I NEED HELP!! Of the following events from the light reactions...

    can someone answer these please!! I NEED HELP!! Of the following events from the light reactions of photosynthesis, which would be expected to occur first? While being split, electrons are taken out of water. Acceptance of electrons by Pc from the cytochrome complex Donation of electrons from reduced Pq to the cytochrome complex Light-induced reduction of the primary elecetron acceptor in the reaction center of PS Il takes place. Question 2 (2 points) The following figure depicts the absorption spectra...

  • Can someone please show me a circuit diagram so i can see how to construct this...

    Can someone please show me a circuit diagram so i can see how to construct this on a bread board i am id 6 yhanks in advance EEET-2251: Course & Projoct Guide 2018 EEET-2251: Cousc &Projoct Guide 2018 affic Light Controller A single switch must set your HC74 based state machine to the initial state (the U state This lab will get you to design a simple controller for a pedestrian crossing based on synchronous digital logic. You will master...

  • Hello, If anyone would be so kind as to help me out with a solution in...

    Hello, If anyone would be so kind as to help me out with a solution in either Java or C++ please and thank you !!! CS 278 Lab3: Quantified statements Write a program that does the following. It should take as a user input ten different integers and store them in a length ten integer array (with no repeated entries). The domain D is the set of entries in this array. Recall that if the domain is a finite set...

  • Must be done in Java. Provide the rest of the code with full comments and explanation and with proper indentation. Use...

    Must be done in Java. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. CODE PROVIDED: import java.util.ArrayList; import java.util.Scanner; public class Problem3 {    public static void main( String [] args ) {        Scanner in = new Scanner( System.in );        //PLEASE START YOUR WORK HERE        //**********************************************************                                                  //**********************************************************        // PLEASE END YOUR WORK HERE        System.out.print("END OF OUTPUT");    } } 20 points! PROBLEM 3: EXTENDED FAMILY Complete this...

  • Breaking it Down Problem One problem that I find in new Java programmers is a tendency...

    Breaking it Down Problem One problem that I find in new Java programmers is a tendency to put too much code in "main()". It is important to learn how to break a program down into methods and classes. To give you practice at this, I have a program that has too much code in main. Your job will be to restructure the code into appropriate methods to make it more readable. I will provide you with lots of coaching on...

  • The menu Here is what the menu should look like when running your program:                              &nbsp

    The menu Here is what the menu should look like when running your program:                                         ***********************************                                         *         FUN MENU             *                                         ***********************************                                                 <S>um of natural integers                                                 <L>eap year check                                                 <C>ount vowels                                                 <E>xit Menu tasks Sum of natural integers ask users to enter an integer (n), then use for loop to compute the sum of the first n integers and finally display the result. If users enter negative integer display an error message. Leap year check...

  • Please help me code the following in: JAVA Please create the code in as basic way...

    Please help me code the following in: JAVA Please create the code in as basic way as possible, so I can understand it better :) Full points will be awarded, thanks in advance! Program Description Write a program that demonstrates the skills we've learned throughout this quarter. This type of project offers only a few guidelines, allowing you to invest as much time and polish as you want, as long as you meet the program requirements described below. You can...

  • Having trouble with the do while/while loop and the switch statement. I got some of the...

    Having trouble with the do while/while loop and the switch statement. I got some of the switch statement but cant get the program to repeat itself like it should.What i have so far for my code is below. Any help is appreciated... i am not sure what I am doing wrong or what i am missing. I am completely lost on the while loop and where and how to use it in this scenario. import java.util.Scanner; public class sampleforchegg {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT