/* CS100M Spring 2004 Lab 10 Background: You need to model a TrafficSignal, which has only two light Bulbs, red and green. In one normal cycle of operation, the red Bulb runs before the green Bulb runs. Each Bulb is designed to run for 120 seconds. However, after 30 seconds of operation, there is a 1% chance that each Bulb will shut off during each of the remaining 90 seconds. Your program needs to determine how much time is used during one cycle of operation of the TrafficSignal. Algorithm for finding the amount of time used in one cycle of operation: + Create a TrafficSignal, which automatically creates a red and green Bulb for itself. + Run a cycle of the TrafficSignal: - Run each Bulb and determine the amount of time that the Bulb was on until it shut off (see the next algorithm). - Add that time to the total amount of time that the TrafficSignal has already been on. + Output the total amount of time that the TrafficSignal was on for one cycle. Algorithm for operating one light Bulb: + Turn the Bulb on. The Bulb will remain on for at least 30 seconds. Assume that a Bulb can shut off only at the end of a second and that each cycle of a loop represents one second of time. + If the Bulb is still on and has not exhausted its duration: - Increment the amount of time that the Bulb has been on. - Check if the Bulb abnormally shut off. - Repeat. The Bulb shuts off if the duration is exhausted. Task: Complete the following classes that implement the above algorithms to find the total amount of time that a TrafficSignal runs in one cycle of operation. Look for comments, fields, and methods that you need to complete. Submit your Java code in a file called Lab10.java. */ // what is this class? public class Lab10 { public static void main(String[] args) { TrafficSignal ts = new TrafficSignal(); // create a new TrafficSignal ts.runOneCycle(); // run one cycle of the Bulbs System.out.println(ts); // output how much time the cycle used } } // what is this class? class TrafficSignal { private Bulb red = _______________ ; // create red light Bulb private Bulb green = ________________ ; // create green light Bulb private int time; // amount of time used in one cycle // Activate the red and green Bulbs in succession: public void runOneCycle() { // fill this in } // Return a String description of how much time the TrafficSignal has run: public String toString() { // complete this method } } // Class TrafficSignal // what is this class? class Bulb { private _______________ ; // color of the light Bulb private _______________ ; // amount of time light Bulb designed to stay on (sec) private boolean on ; // whether or not Bulb is on private int time; // amount of time Bulb has been on (sec) // Create a new Bulb with color and duration: public Bulb(String c, int d) { // complete this constructor } // Return the amount of time that the Bulb was on: public int getTime() { /* complete this method */ } // complete this method // Turn the current Bulb off and on: private void turnOff() { /* complete this method */} private void turnOn() { /* complete this method */ } // Run the current Bulb for the duration of time, after which the Bulb will turn // off. During the operation, the Bulb may randomly turn off after 30 seconds: public void runLight() { // complete this method } // Turn the Bulb off about 1% of the time: private void shutOffAtRandom() { // complete this method } } // Class Bulb class MyMath { public static int myRandom(int low, int high) { // complete this method } }