Question

Using the following Java Class.... public class MicroWave { // Represent possible microwave heat selections private...

Using the following Java Class....

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;
}
}

create a test class that does the following:

1. Creates four instances of a MicroWave:

(a) A blue microwave that is turned "on" and set to "MEDIUM" heat selection.

(b) A green microwave that is turned "off" and set to "LOW" heat selection.

(c) A blue microwave that is turned "on" and set to "HIGH" heat selection.

(d) A microwave created with all default values.

2. Performs an automated test against each Microwave. Test should be placed in a static method with the following signature in the test class.

public static void test(MicroWave[] microWaves)

(a) For simplicity, test method will just iterate over the array of MicroWaves and log a text nessage to a file named "test.log" for each microwave test. Message should consist of the toString() of the microwave along with phrases "pass" or "fail" indicating the result of the test. Microwave "fails" the test if its off.

Sample log file content:

BLUE MEDIUM PASS

GREEN LOW FAIL

0 0
Add a comment Improve this question Transcribed image text
Answer #1

MicroWaveTest.java

import java.io.FileWriter;
import java.io.IOException;

public class MicroWaveTest {
  
public static void test(MicroWave[] microWaves) throws IOException
{
FileWriter fr = new FileWriter("test.log");
for(int i = 0; i < microWaves.length; i++)
{
if(! microWaves[i].isOn())
{
System.out.println(microWaves[i] + " FAIL");
}
else
{
System.out.println(microWaves[i] + " PASS");
}
}
}
  
public static void main(String[] args) throws IOException
{
MicroWave blue = new MicroWave(2, true, "BLUE");
MicroWave green = new MicroWave(1, false, "GREEN");
MicroWave blue2 = new MicroWave(3, true, "BLUE");
MicroWave def = new MicroWave();
  
MicroWave[] microwaves = {blue, green, blue2, def};
  
test(microwaves);
}
}

MicroWave.java

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 = color + " ";
if(heatSelection == LOW)
{
result += "LOW";
}
else if(heatSelection == MEDIUM)
{
result += "MEDIUM";
}
else
{
result += "HIGH";
}
return result;
}
}

Add a comment
Know the answer?
Add Answer to:
Using the following Java Class.... public class MicroWave { // Represent possible microwave heat selections private...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The software I use is Eclipse, please show how to write it, thanks. GeometricObject class public...

    The software I use is Eclipse, please show how to write it, thanks. GeometricObject class public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; protected GeometricObject() { dateCreated = new java.util.Date(); } protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public boolean isFilled() { return filled; } public...

  • Can the folllowing be done in Java, can code for all classes and code for the...

    Can the folllowing be done in Java, can code for all classes and code for the interface be shown please. Modify the GeometricObject class to implement the Comparable interface and define a static max method in the GeometriObject class for finding the larger of two GeometricObject objects. Write a test program that uses the max method to find the larger of two circles, the larger of two rectangles. The GeometricObject class is provided below: public abstract class GeometricObject { private...

  • in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**...

    in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**      * @param args the command line arguments      */         public static void main(String[] args) {       Scanner input=new Scanner(System.in);          Scanner input2=new Scanner(System.in);                             UNOCard c=new UNOCard ();                UNOCard D=new UNOCard ();                 Queue Q=new Queue();                           listplayer ll=new listplayer();                           System.out.println("Enter Players Name :\n Click STOP To Start Game..");        String Name = input.nextLine();...

  • Write a class named Octagon (Octagon.java) that extends the following abstract GeometricObject class and implements the...

    Write a class named Octagon (Octagon.java) that extends the following abstract GeometricObject class and implements the Comparable and Cloneable interfaces. //GeometricObject.java: The abstract GeometricObject class public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; /** Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); } /** Construct a geometric object with color and filled value */ protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color;...

  • public class Fish { private String species; private int size; private boolean hungry; public Fish() {...

    public class Fish { private String species; private int size; private boolean hungry; public Fish() { } public Fish(String species, int size) { this.species = species; this.size = size; } public String getSpecies() { return species; } public int getSize() { return size; } public boolean isHungry() { return hungry; } public void setHungry(boolean hungry) { this.hungry = hungry; } public String toString() { return "A "+(hungry?"hungry":"full")+" "+size+"cm "+species; } }Define a class called Lake that defines the following private...

  • Write an equals method for the Shirt class provided below. Two shirts are logically equivalent if...

    Write an equals method for the Shirt class provided below. Two shirts are logically equivalent if they have the same size, color, and price. public class Shirt { private Size size; private String color; private double price; enum Size { SMALL, MEDIUM, LARGE } public Shirt(Size size, String color, double price) { this.size = size; this.color = color; this.price = price; } public Size getSize() { return size; } public String getColor() { return color; } public double getPrice() {...

  • JAVA Implement a MyQueue class which implements a queue using two stacks. private int maxCapacity...

    JAVA Implement a MyQueue class which implements a queue using two stacks. private int maxCapacity = 4; private Stack stack1; private Stack stack2; Note: You can use library Stack but you are not allowed to use library Queue and any of its methods Your Queue should not accept null or empty String or space as an input You need to implement the following methods using two stacks (stack1 & stack2) and also you can add more methods as well: public...

  • Why is my program returning 0 for the area of a triangle? public class GeometricObjects {...

    Why is my program returning 0 for the area of a triangle? public class GeometricObjects {    private String color = " white ";     private boolean filled;     private java.util.Date dateCreated;     public GeometricObjects() {         dateCreated = new java.util.Date();     }     public GeometricObjects(String color, boolean filled) {         dateCreated = new java.util.Date();         this.color = color;         this.filled = filled;     }     public String getColor() {         return color;     }     public void setColor(String color)...

  • 4. Command pattern //class Stock public class Stock { private String name; private double price; public...

    4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(“BOUGHT: “ + quantity + “x “ + this); } public void sell(int quantity){ System.out.println(“SOLD: “ + quantity + “x “ + this); } public String toString() { return “Product [name=” + name + “, price=” + price + “]”; } } a. Create two command classes that...

  • Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring;...

    Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring; public Person() {    this.numOffspring = 0; } public Person (int numOffspring) {    this.numOffspring = numOffspring; } public Person(String name, int birthYear, double weight, double height, char gender, int numCarryOn, int numOffspring) {    super(name, birthYear, weight, height, gender, numCarryOn);       if(numOffspring < 0) {        this.numOffspring = 0;    }    this.numOffspring = numOffspring; } public int getNumOffspring() {   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT