/**
* This class models an oven appliance for cooking food.
*/
public class Oven {
private final int maxTemperature;
private int currentTemperature = 0;
/**
* Creates an Oven object with a default maximum temperature of 320 degrees Celsius.
*/
public Oven() {
this(320);
}
/**
* Creates an Oven object with a specific maximum temperature.
*
* @param maxTemperature The maximum temperature this oven can be set to. Cannot be a negative number.
* @throws IllegalArgumentException If the maxTemperature is negative
*/
public Oven(int maxTemperature) {
if (maxTemperature < 0) {
throw new IllegalArgumentException("Invalid temperature");
}
this.maxTemperature = maxTemperature;
}
/**
* Sets the current temperature of the oven to the given value.
*
* @param temperature The temperature to set in degrees Celsius
* @throws IllegalArgumentException If the temperature is negative or higher than this oven's maximum temperature.
*/
public void setTemperature(int temperature) {
if (temperature < 0 || temperature > maxTemperature) {
throw new IllegalArgumentException(“Invalid temperature”);
}
this.currentTemperature = temperature;
}
/**
* Gets the current temperature (the oven has no heating or cooling times and changes temperatures instantly).
*
* @return The current temperature in degrees Fahrenheit
*/
public int getCurrentTemperature() {
return (currentTemperature * 9/5) + 32;
}
/**
* Gets the maximum temperature this oven can be set to.
*
* @return The max temperature in degrees Celsius
*/
public int getMaxTemperature() {
return maxTemperature;
}
/**
* Adds an item of food to the oven, potentially changing its state.
*
* @param food The food to be added to the oven
* @param duration The length of time in minutes the food will be in the oven for
* @throws IllegalArgumentException If the food parameter is null, or if the duration is negative
*/
public void insertFood(Food food, int duration) {
if (null == food) {
throw new IllegalArgumentException(“Food may not be null”);
}
if (duration < 0) {
throw new IllegalArgumentException("Duration must be >= 0″);
}
food.cook(currentTemperature, duration);
}
}