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
. In testing, what is the role of an oracle?
ikadub [295]

Answer:

The role of test oracle is to determine if a test has passed or failed. Oracle compares the outputs of the system under a  test, for a given test-case input, and the output(s) that should have. A test oracle works on specifying constraints on the output(s) for a set of inputs. An oracle could be:

  • a program which tells if the output is correct.
  • documentation that specifies the correct output for inputs.
  • a human that can tell whether it is correct an output.

5 0
3 years ago
Choose the correct term to complete the sentence.
Andre45 [30]

Answer:

Technology

Explanation:

Edge 2021

8 0
2 years ago
What does the headgear of a mine do
deff fn [24]
Hard to answer to short but I will try the head gear let's you talk to people on the internet
5 0
3 years ago
Read 2 more answers
Public class Bird
Anna007 [38]

Answer:

Answer below.

Explanation:

You are creating an object of bird "b" with a talon strength of 5 and a beak of 5.

public Hawk(int talon, int beak)

{

super(beak);

talonStrength = talon;

}

Please mark brainliest if this is the answer you were looking for

Please mark brainliest if this is the answer you were looking for

6 0
3 years ago
The hypothalamus controls the anterior pituitary by means of: a. releasing hormones b. second messengers c. third messengers d.
scoundrel [369]

Answer:

a. releasing hormones

Explanation:

The hypothalamus controls the anterior pituitary by means of corticotropin-releasing hormone (CRH). The hormone CRH is encoded by the CRH gene on eighth human chromosome. The anterior pituitary in turn regulates other endocrine glands by means of Adrenocorticotrophic Hormone (ACTH). These actions form part of the Hypothalamic–pituitary–adrenal(HPA) axis which is one of the important neuroendocrine systems in humans.

7 0
3 years ago
Other questions:
  • 9. Name at least two types of hard drives?
    6·1 answer
  • Tim has an old server computer that his company uses as a backup. One of the hard drives has gone bad and needs to be replaced.
    13·1 answer
  • When a range of IP addresses is set aside for client devices, and one of these IPs is issued to these devices when they request
    14·1 answer
  • 4. Scientists are not concerned with the human impact on the environment. True or False?
    6·2 answers
  • Load the titanic sample dataset from the Seaborn library into Python using a Pandas dataframe, and visualize the dataset. Create
    10·1 answer
  • A person who wants to buy a compact disc (cd) has just enough money to buy one, and chooses cd a instead of cd
    10·2 answers
  • Please help me I need a help
    13·1 answer
  • HELP TIMED!!!!!!!!!!!!!!!!!!!!
    5·2 answers
  • If you were practicing keyboarding and the exercise contained the letters j, k, l, m, n, and b, what section of the
    14·1 answer
  • A leading global vendor of computer software, hardware for computer, mobile and gaming systems, and
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!