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
This operating system was used by individual computers an required users to type commands
nika2105 [10]
Hey there!

The operating system that functions from typing commands is called a Command–Line–Based OS. Examples of this type of OS include UNIX and MS–DOS made by Microsoft. These features white or green text on a black screen and were primarily meant for professionals who had to learn lots of commands rather than everyday users. 

Hope this helped you out! :-)
7 0
2 years ago
Please answer this question​
Andrews [41]
Can you please upload it again
7 0
2 years ago
What type of hardware and software does Instagram use?
Vlad [161]

Answer:

Social networking platform and  WindowsandroidIOS

Explanation:

Social media mostly uses Social networking platform and  WindowsandroidIOS.

Hope this helps!

Feel free to ask if you have anymore questions!

5 0
2 years ago
Read 2 more answers
Which SCSI standard allows for the technique known as “hot swapping”? Ultra SCSI Original SCSI Serial SCSI Fast-Wide SCSI
miss Akunina [59]

Answer:

Serial SCSI

Explanation:

Hot swapping can be defined as a process which typically involves fitting or replacing CD-ROM drive, hard-disk drive, power supply or other peripheral devices while a computer system is powered on. Thus, it allows for the installation or removal of a peripheral device from a computer while power is still being supplied to the computer i.e without having to shutdown the computer.

Serial SCSI is a SCSI standard which allows for the technique known as “hot swapping” because it's a point to point connection that is designed to move data to and from computer storage serially.

6 0
3 years ago
While accessing mail through the mail command interface, a user sees 5 new messages in his mailbox. Since the second message app
RUDIKE [14]

Answer:

The answer is "print 2".

Explanation:

The mail command, which is also known as the return path, bounce address, as well as mfrom, and sends the back address. This command is used to set the message receiver, order RCPT. It's also composed of the message for the header, and it is the empty line of the message body, and in this command to read the second message we use the print 2 message.

7 0
2 years ago
Other questions:
  • Which of the following is important to do when downloading a game to your
    8·1 answer
  • (It science question)
    9·1 answer
  • A tablet computer transmits a file over a wi-fi link to an access point.
    13·1 answer
  • You are required to design a 4-bit even up-counter using D flip flop by converting combinational circuit to sequential circuit.
    15·1 answer
  • Jenny is the project manager and her company. She needs to break her current project into parts that her employees can work on.
    10·1 answer
  • We will pass in a value N. Write a program that outputs the complete Fibonacci sequence for N iterations. Important: If N is 0,
    13·1 answer
  • Write a function findWithinThreshold that identifies the elements of a given array that are inside a threshold value. Takes the
    13·1 answer
  • When would you use the AutoFit to Contents option?
    15·1 answer
  • Choose all items that represent examples of good website accessibility.
    8·2 answers
  • How many different four-letter combinations for a locker password can you make with the lowercase and uppercase forms of the fir
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!