Question

In: Computer Science

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;

}

}

Question 21

Not yet answered

Marked out of 1.00

Flag question

Question text

D3a - [1 Mark]

How many field attributes are there in the TrafficLight class?

Answer:

Question 22

Not yet answered

Marked out of 1.00

Flag question

Question text

D3b - [1 Mark]

Name a field attribute for this class.

Answer:

Question 23

Not yet answered

Marked out of 1.00

Flag question

Question text

D3c - [1 Mark]

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

Answer:

Question 24

Not yet answered

Marked out of 1.00

Flag question

Question text

D3d - [1 Mark]

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

Answer:

Question 25

Not yet answered

Marked out of 1.00

Flag question

Question text

D3e - [1 Mark]

What is the output type for the setStopLight method

Answer:

Question 26

Not yet answered

Marked out of 3.00

Flag question

Question text

D3f - [3 Marks]

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

Solutions

Expert Solution

Given code:

public class TrafficLight {

String stopLight = "red";

String waitLight;

String goLight;

public void setStopLight(String colour) {

stopLight = colour;

}

public String getGreenLight() {

return goLight;

}

}

.

Question 21

How many field attributes are there in the TrafficLight class?

3

  1. stopLight
  2. waitLight
  3. goLight

.

Question 22

Name a field attribute for this class.

stopLight

.

Question 23

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

getGreenLight

Explanation:

accessor is a method which returns value of attribute of an object, here getGreenLight returns value of goLight.

.

Question 24

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

setStopLight

Explanation:

mutator is a method which modifies value of attribute of an object, here setStopLight modifies value of stopLight.

.

Question 25

What is the output type for the setStopLight method

void

Explanation:

because setStopLight is an mutator method, it doesn't output something ie void.

.

Question 26

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

TrafficLight() {

stopLight = "red";

waitLight = "yellow";

goLight = "green";

}

.


Related Solutions

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...
Use the definition of incidence taught in class, and answer the following questions. Be sure to...
Use the definition of incidence taught in class, and answer the following questions. Be sure to show your work. 1.      Spring fever! Epidemiologists and teachers alike have noticed the cyclic occurrence of the dreaded spring fever. Students afflicted with this disease exhibit certain listlessness in class. And they seem to stare out the windows with remarkable tenacity. Why, it’s almost as if the trees growing outside are more interesting than doing algebra. (Gasp!) At Metropolitan High School, teachers have been...
Use the case below to answer the following question(s) (Total marks = 100) A certain restaurant...
Use the case below to answer the following question(s) (Total marks = 100) A certain restaurant located in a resort community is owned and operated by Karen Payne. The restaurant just completed its third year of operation. During this time, Karen sought to establish a reputation for the restaurant as a high quality dining establishment that specialises in fresh seafood. The efforts made by Karen and her staff proved succesful, and her restaurant is currently one of the best and...
A incomplete definition of a class Temperature is given below: public class Temperature { private double...
A incomplete definition of a class Temperature is given below: public class Temperature { private double value[] = {36.5, 40, 37, 38.3}; } [6] (i) Copy and put it in a new class. Write a method toString() of the class, which does not have any parameters and returns a string containing all the values separated by newlines. When the string is printed, each value should appear on a line in the ascending order of their indexes. Copy the content of...
Use the following information to answer the questions below:
Use the following information to answer the questions below: note: all sales are credit sales Income Stmt info: 2016 2017 Sales $ 975,000 $        1,072,500 less Cost of Goods Sold: 325,000 346,125 Gross Profit 650,000 726,375 Operating Expenses 575,000 609,500 Earnings before Interest & Taxes 75,000 116,875 Interest exp 25,000 31,000 earnings before Taxes 50,000 85,875 Taxes 20,000 34,350 Net Income $ 30,000 $              51,525 Balance Sheet info: 12/31/2016 12/31/2017 Cash 60,000 $ 63,600 Accounts Receivable 80,000 $ 84,000 Inventory...
Use the following data to answer the questions below:
Use the following data to answer the questions below:             Q                 VC             MC           AVC              1                 $10              ___            ___                                   2                16              ___            ___                       3                20              ___            ___                                   4                25              ___            ___              5                31              ___            ___              6                  38              ___            ___                  7                  46              ___            ___8                  55              ___            ___9                  65              ___            ___         a. Calculate the marginal cost and average variable cost for each level of production.b. How much would the firm produce if it could sell its product for...
Use the table below to answer the following two questions: Units of output Total fixed cost...
Use the table below to answer the following two questions: Units of output Total fixed cost Total variable cost 1 150 50, 2 150 96, 3 150 140, 4 150 180 1) What is the marginal cost of producing the third unit of output? a) $20 b) $44 c) $70 d) this cannot be determined from the data 2) At which unit of production do diminishing returns become evident? a) 1 b) 2 c) 3 d) 4 3) Accounting costs...
4 Q5 Total Marks 8 Marks 8 Marks 8 Marks 8 Marks 8 Marks 40 Marks...
4 Q5 Total Marks 8 Marks 8 Marks 8 Marks 8 Marks 8 Marks 40 Marks               Q1: A cantilever beam having span ‘L’ m was subjected to a uniformly distributed load of magnitude 8 kN/m for a distance of ‘0.6 L’ from the free end and two concentrated loads one of magnitude 15 kN at a distance ‘0.25 L’ m from the free end while the other of magnitude ‘22’ kN at a distance ‘0.6 L’ m from the...
Multiple Choice (20 marks) Query Questions (use the tables below to answer the 5 query questions...
Multiple Choice Query Questions (use the tables below to answer the 5 query questions below) The Business. A retail company sells electronics items by phone and on its web site. The company records information about each item sold in a table called Sales. A few rows of the Sales table in the database are shown below: Sales table (primary key = SaleID and ItemID) SaleID ItemID CustomerID ItemType SaleDate 101 151 52 4 1/1/2019 101 176 52 1 1/1/2019 102...
Use the table below to answer the questions below. The following prices are for call and...
Use the table below to answer the questions below. The following prices are for call and put options on a stock priced at $50.25. The March options have 90 days remaining and the June options have 180 days remaining. In your profit answers below, assume that each transaction is scaled by 100, reflecting the size of option contracts. Calls Puts Strike March June March June 45 6.85 8.45 1.20 2.15 50 3.90 5.60 3.15 4.20 55 1.95 3.60 6.15 7.00...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT