Use the class definition below to answer the following questions.
public class TrafficLight {
String stopLight = "red";
String waitLight;
String goLight;
public void setStopLight(String colour) {
stopLight = colour;
}
public String getGreenLight() {
return goLight;
}
}
1. How many field attributes are there in the TrafficLight class?
2. Name a field attribute for this class.
3. What is the name of the method that is an accessor?
4. What is the name of the method that is a mutator?
5. What is the output type for the setStopLight method
6. Write a Constructor for the TrafficLight class that sets stopLight value to “red”, waitLight to “yellow” and goLight to “green”?
How many field attributes are there in the TrafficLight class? Answer: 3 Name a field attribute for this class. Answer: stopLight What is the name of the method that is an accessor? Answer: getGreenLight What is the name of the method that is a mutator? Answer: setStopLight What is the output type for the setStopLight method Answer: void Write a Constructor for the TrafficLight class that sets stopLight value to “red”, waitLight to “yellow” and goLight to “green”? public TrafficLight() { stopLight = "red"; waitLight = "yellow"; goLight = "green"; }
Get Answers For Free
Most questions answered within 1 hours.