The `Oven` class has private variables `maxTemp` and `currentTemp`, a constructor that initializes these variables within specified constraints, and methods to get the maximum temperature, current temperature, turn off the oven, check if the oven is on, and preheat the oven to a specified temperature.
Here is the implementation of the `Oven` class with the described variables, constructors, and methods:
```java
public class Oven {
private int maxTemp;
private int currentTemp;
public Oven(int maxTemperature, int startTemperature) {
// Initialize maxTemp with a value between 0 and 500
this.maxTemp = (maxTemperature >= 0 && maxTemperature <= 500) ? maxTemperature : 500;
// Initialize currentTemp with a value between 0 and maxTemp
this.currentTemp = (startTemperature >= 0 && startTemperature <= this.maxTemp) ? startTemperature : 0;
}
public int getMaxTemp() {
return maxTemp;
}
public int getCurrentTemp() {
return currentTemp;
}
public void turnOff() {
if (currentTemp > 0) {
currentTemp = 0;
System.out.println("Turning the oven off.");
}
}
public boolean isOn() {
return currentTemp > 0;
}
public void preheat(int temp) {
if (temp > maxTemp) {
currentTemp = maxTemp;
} else if (temp > 0) {
currentTemp = temp;
}
// If temp is less than or equal to 0, do nothing.
}
}
```