In: Computer Science
(JAVA)
Referencing the class Oven, complete the Constructor and set method for the instance variable temp.
Use the same requirement for the constructor for the set temperature method.
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
Oven.java
package c15;
public class Oven {
private int temp;
private String power;
private String color;
public Oven(int temp,String c) {
if(temp>=0 &&
temp<=500) {
this.temp =
temp;
}else {
this.temp =
0;
}
power = "off";
color = c;
}
public void setTemp(int temp) {
if(temp>=0 &&
temp<=500) {
this.temp =
temp;
}else {
this.temp =
0;
}
}
public void setPower(String power) {
this.power = power;
}
public void setColor(String color) {
this.color = color;
}
public int getTemp() {
return temp;
}
public String getPower() {
return power;
}
public String getColor() {
return color;
}
@Override
public String toString() {
return "Oven [temp=" + temp + ",
power=" + power + ", color=" + color + "]";
}
public static void main(String[] args) {
Oven o = new Oven(120,
"Red");
System.out.println(o);
}
}
output