Question

In: Computer Science

(JAVA) Referencing the class Oven, complete the Constructor and set method for the instance variable temp....

(JAVA)

Referencing the class Oven, complete the Constructor and set method for the instance variable temp.

  • Constructor checks if the temperature is between 0 and 500. If the temperature does not fit the requirement, then set the temperature to be zero. Otherwise, set it to be the value passed to the constructor.
  • Set the power to be off.
  • Set the String to be the color passed to the constructor.

Use the same requirement for the constructor for the set temperature method.

Solutions

Expert Solution

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


Related Solutions

its java language. 1. Create a class called Car. A Car has instance variables, constructor parameters,...
its java language. 1. Create a class called Car. A Car has instance variables, constructor parameters, setters, and getters for “year manufactured” and “make” and “model” (e.g. 2016 Honda Civic) 2. Create a class called CarLot which has an array of 5 Car references. There are two constructors: (a) One constructor takes no parameters and simply populates the array with these cars: cars[0] = new Car(2016, “honda”, “civic”); cars[2] = new Car(2017, “Lamborghini”, “aventador”); cars[3] = new Car(2000, null, “caravan”);...
(Java Problem) Create a Produce class that have an instance variable of type String for the...
(Java Problem) Create a Produce class that have an instance variable of type String for the name, appropriate constructors, appropriate accessor and mutator methods, and a public toString() method. Then create a Fruit and a Vegetable class that are derived from Produce. These classes should have constructors that take the name as a String, the price (this is the price per box) as a double, the quantity as an integer, and invoke the appropriate constructor from the base class to...
Class Exercise: Constructor using JAVA Let’s define a Class together and have a constructor while at...
Class Exercise: Constructor using JAVA Let’s define a Class together and have a constructor while at it. - What should the Class object represent? (What is the “real life object” to represent)? - What properties should it have? (let’s hold off on the methods/actions for now – unless necessary for the constructor) - What should happen when a new instance of the Class is created? - Question: What are you allowed to do in the constructor? - Let’s test this...
Java Implement a class MyInteger that contains: • An int data field/instance variable named value that...
Java Implement a class MyInteger that contains: • An int data field/instance variable named value that stores the int value represented by this object. • A constructor that creates a MyInteger object for a default int value. What default value did you choose? What other values did you consider? Why did you make this choice? • A constructor that creates a MyInteger object for a specified int value. • A getter method, valueOf(), that returns value. • A setter method,...
in java Create a class City with x and y as the class variables. The constructor...
in java Create a class City with x and y as the class variables. The constructor with argument will get x and y and will initialize the city. Add a member function getDistanceFrom() to the class that gets a city as the input and finds the distance between the two cities.
- Create a java class named SaveFile in which write the following: Constructor: The class's constructor...
- Create a java class named SaveFile in which write the following: Constructor: The class's constructor should take the name of a file as an argument A method save (String line): This method should open the file defined by the constructor, save the string value of line at the end of the file, and then close the file. - In the same package create a new Java class and it DisplayFile in which write the following: Constructor: The class's constructor...
Question 1 price is an instance variable of a class. Inside that class there is a...
Question 1 price is an instance variable of a class. Inside that class there is a method public void change(int price). From inside the method " change" how do we refer to the instance variable price and not the parameter price? Answer: Question 2 A method of a class can access which of the following: 1 global variables in the same scope 2. local variables defined within the method 3. the instance variables of its class 4. its parameters Question...
USING JAVA: complete these one method in the BasicBioinformatics class /** * Class BasicBioinformatics contains static...
USING JAVA: complete these one method in the BasicBioinformatics class /** * Class BasicBioinformatics contains static methods for performing common DNA-based operations in * bioinformatics. * * */ public class BasicBioinformatics { /** * Calculates and returns the reverse complement of a DNA sequence. In DNA sequences, 'A' and 'T' * are complements of each other, as are 'C' and 'G'. The reverse complement is formed by * reversing the symbols of a sequence, then taking the complement of each...
USING JAVA: complete the method below in the BasicBioinformatics class. /** * Class BasicBioinformatics contains static...
USING JAVA: complete the method below in the BasicBioinformatics class. /** * Class BasicBioinformatics contains static methods for performing common DNA-based operations in * bioinformatics. * * */ public class BasicBioinformatics { /** * Calculates and returns the number of times each type of nucleotide occurs in a DNA sequence. * * @param dna a char array representing a DNA sequence of arbitrary length, containing only the * characters A, C, G and T * * @return an int array...
in bluej java Write an application with two classes. Class NumberUtility has one instance variable n...
in bluej java Write an application with two classes. Class NumberUtility has one instance variable n of type int. Constructor initializes instance variable n by using input parameter n. public NumberUtility(int n) Class also has the following methods:   public int getN()                              // Returns instance variable n public boolean isOdd()                  // Returns true if number n is odd and returns false otherwise. public boolean isEven()               // Returns true if number n is even and returns false if it is odd.      // Implement method by...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT