A class called Traffic is designed as shown in the class diagram. It contains: O
ID: 3838490 • Letter: A
Question
A class called Traffic is designed as shown in the class diagram. It contains: One String private instance variable: location. One int private instance variable: numberOfCars. One constructor that takes no parameters. public setters: setLocation (String) that sets the variable location to the value of the input parameter and setNumberOfCars(int) that sets the variable numberOfCars to the input parameter. public getters: getLocation() that returns the instance variable location and getNumberOfCars() that returns the instance variable numberOfCars. public report() that prints "There are [numberOfCars] cars at [location]". public trafficJam(int) that takes numberOfCars as input parameter and returns true if numberofCars is larger than 100 and false otherwise. Implement the Traffic class in the answer box below.Explanation / Answer
public class Traffic {
private String location;
private int numberOfCars;
public Traffic()
{
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public int getNumberOfCars() {
return numberOfCars;
}
public void setNumberOfCars(int numberOfCars) {
this.numberOfCars = numberOfCars;
}
public void report()
{
System.out.println("There are " + getNumberOfCars() + " cars at " + getLocation());
}
public boolean trafficJam(int numberOfCars)
{
return numberOfCars > 100;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.