Question

Use the class definition below to answer the following questions. public class TrafficLight { String stopLight...

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;

}

}

How many field attributes are there in the TrafficLight class?

Name a field attribute for this class.

What is the name of the method that is an accessor?

What is the name of the method that is a mutator?

What is the output type for the setStopLight method

Write a Constructor for the TrafficLight class that sets stopLight value to “red”, waitLight to “yellow” and goLight to “green”?

Homework Answers

Answer #1
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";
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Use the class definition below to answer the following questions. public class TrafficLight { String stopLight...
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; } How many field attributes are there in the TrafficLight class? Name a field attribute for this class. What is the name of the method that is an accessor? What is the name of the method that is a mutator? What is the...
Use the class definition below to answer the following questions. public class TrafficLight { String stopLight...
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...
Use the class definition below to answer the following questions. [Total 8 Marks] public class TrafficLight...
Use the class definition below to answer the following questions. [Total 8 Marks] 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...
public class Auto { private String make; private String model; private int year; } a) write...
public class Auto { private String make; private String model; private int year; } a) write a default constructor for the Auto Class n) Write a constructor to initialize all instance variables c) write accessor and mutator for make variable d) create an onject name it myAuto with values of Toyota, Camry, and 2016
Write a pseudocode for the following java programs: public class Item {    private String name;...
Write a pseudocode for the following java programs: public class Item {    private String name;    private double cost;    public Item(String name, double cost) {        this.name = name;        this.cost = cost;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public double getCost() {        return cost;    }    public void setCost(double cost) {...
Write the following problem in Java Create a class Dog, add name, breed, age, color as...
Write the following problem in Java Create a class Dog, add name, breed, age, color as the attributes. You need to choose the right types for those attributes. Create a constructor that requires no arguments. In this constructor, initialize name, breed, age, and color as you wish. Define a getter and a setter for each attribute. Define a method toString to return a String type, the returned string should have this information: “Hi, my name is Lucky. I am a...
Part 1 Given the following code: public class MyClass { private double score; private String studentID;...
Part 1 Given the following code: public class MyClass { private double score; private String studentID; //code of the class ..... } //end of MyClass Code a default constructor and an overloaded constructor of MyClass that will assign values to its two instance fields: Please write in JAVA Part 2 Continue from question about, code an mutator of instance field called studentID:
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){    strName = " ";    strSalary = "$0";    } public Employee(String Name, String Salary){    strName = Name;    strSalary = Salary;    } public void setName(String Name){    strName = Name;    } public void setSalary(String Salary){    strSalary = Salary;    } public String getName(){    return strName;    } public String getSalary(){    return strSalary;    } public String...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class called Student which implements Duty. Class Student adds 1 data field, id, and 2 methods, getId and setId, along with a 1-argument constructor. The duty of a Student is to study 40 hours a week. b. Write a class called Professor which implements Duty. Class Professor adds 1 data field, name, and 2 methods, getName and setName, along with a 1-argument constructor. The duty...