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
Assuming you have a TCF free student checking account, how many maximum overdraft fees can you incur in one day?
kodGreya [7K]

Answer:

8

Explanation:

7 0
3 years ago
this feature offered by mutual funds allows investors to switch from one mutual fund to another within a fund families.
Musya8 [376]

The feature is called Fund Switching, also known as exchange privileges.

<h3>What is fund switching?</h3>

This feature is called "fund switching" or "exchange privileges." It allows investors to move their investment from one mutual fund to another within the same fund family without incurring a sales charge or fee.

Fund switching is typically offered by mutual fund companies as a way to give investors flexibility and control over their investments. It allows investors to respond to changing market conditions or to rebalance their portfolios without incurring additional costs.

Some mutual fund companies may impose certain restrictions on fund switching, such as limiting the number of exchanges that can be made within a given time period.

It is important for investors to understand these restrictions and to carefully consider their investment decisions before making any changes to their portfolios.

To Know More About Mutual Funds, Check Out

brainly.com/question/9965923

#SPJ1

3 0
1 year ago
According to the government, employees have a right to understand the risks associated with the materials they work with.
Alex
True. They require a MSDS (Material Safety Data Sheet) for each chemical that a business receives.
3 0
3 years ago
What is Stefen Salvators mom name? For the tvd fans
jekas [21]

Answer:

Lillian "Lily" Salvatore

Explanation:

8 0
2 years ago
Read 2 more answers
Need answer ASAP
Mnenie [13.5K]

Answer:

c is the correct awnser ( to code and test )

6 0
3 years ago
Read 2 more answers
Other questions:
  • When a cache block has been modified since being read from main memory?
    10·2 answers
  • Although the original BBS system was simple, it increased people's ability to communicate
    14·1 answer
  • Which is the correct process for adding page numbers to a spreadsheet you will print? A. Click Page Break Preview. Type the page
    7·1 answer
  • 15) the following statement describes government depository librearies , except:
    12·1 answer
  • The calculation of the likelihood of an attack coupled with the attack frequency to determine the expected number of losses with
    12·1 answer
  • Whats yall favv scary movie
    11·1 answer
  • Select the correct answer.
    5·1 answer
  • How do people decide their ethical behavior
    13·2 answers
  • Years ago when working a helpdesk, the most common question asked, almost daily, was about resetting passwords. What type of kno
    11·1 answer
  • In cell b12 create a formula using max f7nction to calculate maximum value in B4:B9
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!