Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Program. Design a class named MicroWave to represent a microwave. The class

ID: 3825836 • Letter: J

Question

Java Program. Design a class named MicroWave to represent a microwave. The class must contain the following:

1. Three constants named LOW, MEDIUM, HIGH to represent possible microwave heat selections.

2. A private int data field named heatSelection that specifies the microwave heat selection(default is MEDIUM)

3. A private boolean data field named ON that specifies whether the microwave is on(default is false)

4. A string data field named color that specifies the color of the microwave.(default color is black)

5. A no-arg constructor that creates a microwave with default values.

6. A constructor that takes all three data fields.

7. Accessor methods for all three data fields.

8. Mutator methods for the heatSelection and on data fields.

9. A toString() method implementation that returns the color and heat selection ("LOW', "MEDIUM", "HIGH" as a text string) of the microwave.

Explanation / Answer

public class MicroWave {

// Represent possible microwave heat selections
private final int LOW = 1;
private final int MEDIUM = 2;
private final int HIGH = 3;
  
// specifies the microwave heat selection(default is MEDIUM)
private int heatSelection;
  
// specifies whether the microwave is on
private boolean on;
  
private String color;
  
public MicroWave(int heatSelection, boolean on, String color) {
this.heatSelection = heatSelection;
this.on = on;
this.color = color;
}
  
public MicroWave() {
this.heatSelection = MEDIUM;
this.on = false;
this.color = "black";
}

public int getHeatSelection() {
return heatSelection;
}

public void setHeatSelection(int heatSelection) {
this.heatSelection = heatSelection;
}

public boolean isOn() {
return on;
}

public void setOn(boolean on) {
this.on = on;
}

public String getColor() {
return color;
}

@Override
public String toString() {
String result = "MicroWave color=" + color + " heat selection: ";
if(heatSelection == LOW)
{
result += "LOW";
}
else if(heatSelection == MEDIUM)
{
result += "MEDIUM";
}
else
{
result += "HIGH";
}
return result;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote