98.0k views
2 votes
A car's check engine light will turn on and stay on if the car has traveled at least 5,000 miles since the last oil change. Write a conditional statement to determine if check engine light is on.

User Darcara
by
2.9k points

1 Answer

4 votes

Answer:

Step-by-step explanation:

The following code is written in Java. It creates a Cars class that has a variable for checkEngine and carMiles. Then the constructor accepts the carMiles and checks if the carMiles is greater or less than 5000 and adjusts the checkEngine light or not. Two test objects have been created and the output can be seen in the attached image below.

class Cars {

boolean checkEngine;

int carMiles;

public Cars(int carMiles) {

this.carMiles = carMiles;

if (carMiles > 5000) {

this.checkEngine = true;

} else {

this.checkEngine = false;

}

}

public boolean isCheckEngine() {

return checkEngine;

}

public int getCarMiles() {

return carMiles;

}

}

A car's check engine light will turn on and stay on if the car has traveled at least-example-1
User Bgies
by
3.4k points