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]
3 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]3 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
Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
Lorico [155]

Answer:

#here is code in Python.

#read the value n from user

n=int(input("enter the value of n:"))

#variable to store the total sum

sum_n=0

for i in range(1,n+1):

# find the sum of series

   sum_n=sum_n+1/i

#print the sum

print("sum of the series is: ",sum_n)

Explanation:

Read the value of n from user. Create and initialize a variable sum_n with 0. Run a for loop to calculate sum.Initially sum_n is 0, then for value of i=1  1/i will be added to the sum_n.Then in next iteration for i=1, 1/2 added to sum_n. Similarly loop will run util i equals to n.Then sum_n will store the sum of the

series.

Output:

enter the value of n:5

sum of the series is:  2.283333333333333

3 0
3 years ago
Help please, this whole assignment is due in 15 minutes
Butoxors [25]

I believe the answer is:

1. Prepare the data

2. Select all data

3. Use the copy command

4. Open new file

5. Use the paste command

I really hope this helps! Good luck!

6 0
3 years ago
How can you encrypt and decrypt a message in cryptography
ser-zykov [4K]
There are two main types of encryption - <span>symmetric and asymmetric. 

Using symmetric encryption, you use a single secret key that is used to both encrypt and decrypt the data. This form of encryption has been used way before computers! Without this key it is very hard to decrypt a message. However, the issue with this is that if you want to send an encrypted message, you also have to send a key to them, and </span>if your somebody unintended intercepts the key, they can read the message.

What's the solution? Asymmetric cryptography or public key encryption. Asymmetric cryptography uses encryption that splits the key into two smaller keys. One of the keys is public and one is kept private. A good metaphor for understanding this is the public key is the lock, and the private key is the key. You can encrypt a message to send to somebody with their public key, locking it, which they can then decrypt, unlock, with their private key. And vice versa. So with this kind of encryption it's very difficult to decrypt a message for anybody but the owner as it's much harder to steal when it doesn't need to leave their computer, but easy to encrypt messages to send to them

5 0
3 years ago
Allows a service provider organization to own and manage the infrastructure (including computing, networking, and storage device
djverab [1.8K]

Answer:

The answer is "Public Cloud computing".

Explanation:

It is a type of technology that focusing on domain-specific resources rather than using dedicated servers or intelligent machines. All services are provided as well as used throughout the Network and per user are paid, and certain options were wrong which can be described as follows:

  • In option 1, it is used to describe the details, it doesn't store data.
  • In option 2, It is used in the organization.
  • In option 3, It is used for courts or legal documentations.
7 0
4 years ago
Mt. Everest, the highest mountain in the world, is located in Asia.<br><br> True<br> False
Roman55 [17]
True, it is located on the border of Nepal and Tibet.
8 0
3 years ago
Other questions:
  • Which computer device is used to capture or copy a photograph to place in a report?
    14·1 answer
  • ____ devices are high-performance storage systems that are connected individually to a network to provide storage for the comput
    5·1 answer
  • Routing protocols that enable routers to communicate beyond neighboring routers, allowing each router to independently map the n
    7·1 answer
  • )duplicate hash code
    15·1 answer
  • A look to different section of the same page is known as_____.
    7·1 answer
  • FOR DIGITAL DESIGN/ PHOTOGRAPHY
    5·2 answers
  • Consider the algorithm for determining whether a sequence of parentheses is balanced (has correct nesting). The pseudo code for
    10·1 answer
  • PLS FAST DONT EXPLAIN
    13·1 answer
  • ANSWER ASAP!!!!!!
    12·2 answers
  • Topic: Video Games.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!