1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
N76 [4]
2 years ago
15

Implement a class that simulates a traffic light. The next function advances the color in the usual way, from green to yellow to

red, then again to green. Provide two constructors, of the public interface. Also supply a member function that yields the number of times that this traffic light has been red.
Computers and Technology
1 answer:
marusya05 [52]2 years ago
7 0

Answer:

Explanation:

The following is written in Java. It creates the trafficLight class which holds the currentLight string variable and a int count variable for the number of times the light has been red. It also contains two constructors one that takes the currentLight as a parameter and one that does not. Finally, it has the next() method which analyzes the currentLight status and changes it to the next light. Output can be seen in the attached picture below.

class Brainly

{

   public static void main(String[] args)

   {

       trafficLight traffic_light = new trafficLight();

       System.out.println("Current Light: " + traffic_light.currentLight);

       traffic_light.next();

       System.out.println("Current Light after change: " + traffic_light.currentLight);

       

   }

}

class trafficLight {

   String currentLight;

   int count = 0;

   public trafficLight(String currentLight) {

       this.currentLight = currentLight;

   }

   public trafficLight() {

       this.currentLight = "red";

       count++;

   }

   public void next() {

       if (this.currentLight == "green") {

           this.currentLight = "yellow";

       } else if (this.currentLight == "yellow") {

           this.currentLight = "red";

           count++;

       } else {

           this.currentLight = "green";

       }

   }

}

You might be interested in
What is the internet?
Inessa [10]
 this is the definition:<span>a global computer network providing a variety of information and communication facilities, consisting of interconnected networks using standardized communication protocols.</span>
3 0
3 years ago
Read 2 more answers
Which snippet of code is in XML?
11111nata11111 [884]

Answer:

still need help with this or you got it done if not lmak asap and I can help ya:)

5 0
3 years ago
Por que se dice que la tecnología ha tenido muchos aportes positivos para la sociedad pero también nos ha hecho dependientes de
Dominik [7]

Answer:

??????????????

Explanation:

6 0
2 years ago
Operating systems that have windows and icons have which type of user interface?
777dan777 [17]
A GUI (Graphical User Interface)
4 0
3 years ago
Which of the following actions taken by the Fed will increase the nation’s money supply? (Select all that apply.)
pashok25 [27]

Answer:

it is A.Lowering the reserve ratio

5 0
2 years ago
Other questions:
  • You send a report to your boss for feedback and she returns it to you with her edits noted in the electronic file. This Word fea
    11·1 answer
  • The network topology in which each device is connected directly to a central network switch
    9·1 answer
  • Where can you find gradpoint answers
    13·2 answers
  • What is the system of phonographic disc recordings paired with a projector called?
    9·1 answer
  • Another html/css assignment, drop css code below, thank you
    15·1 answer
  • A reflexive pronoun is a pronoun
    6·1 answer
  • Describe advantages and disadvantages for microprocessor controlled devices in the household.
    7·1 answer
  • PLEASE HELP! WILL MARK AS BRAINLIEST!
    6·2 answers
  • Difference between hacking and cracking not hackers and crackers ​
    10·1 answer
  • Sftp uses which mechanism to provide security for authentication and data transfer?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!