Question

You have a class named AirConditioner that has a private boolean field named on. It has...

You have a class named AirConditioner that has a private boolean field named on. It has method named turnOn that sets the field to true and one named turnOff that set it to false. It also has a method named isOn that returns the value of the on field. You have made an object of this class named myAC. If it is not already on, you want the AC on. Fill in the blank to make this happen.

if (!myAC.isOn()) {

___________________

}

Homework Answers

Answer #1

The answer is : myAC.turnOn()

Explanation:-

Firstly, if AC is not on then myAC.isOn() will return false which on putting not before false will convert it to true i.e. (!myAC.isOn()) = true . So we go inside if condition only when AC is not on.

Now as we can call the methods using the object of class , in this case it is myAC (example of calling method - inside if condition i.e. myAC.isOn() )

Since turnOn method sets the boolean field to true , therefore we are making a call to turnOn() method using myAC object of class to turn On the AC if it is not already on , as required in the question.

Know the answer?
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
Similar Questions
Create a field with the boolean value of goodBoi. In the constructor, set your good boi...
Create a field with the boolean value of goodBoi. In the constructor, set your good boi to being false, as all dogs has deserve being called a good boiii. Make a method makeGoodBoi, which sets the good boi value to being true. Make a method isGoodBoi which returns the value the good boi field (hint: it returns a boolean value). Now we need a method called whosAGoodBoi. If the doggo is indeed a good boi, then print: "[doggo] is such...
Design a Java class named Polygon that contains:  A private int data field named numSides...
Design a Java class named Polygon that contains:  A private int data field named numSides that defines the number of sides of the polygon. The default value should be 4.  A private double data field named sideLength that defines the length of each side. The default value should be 5.0.  A private double data field named xCoord that defines the x-coordinate of the center of the polygon. The default value should be 0.0.  A private double...
Q:Could you fill in the blank。 class Employee{ // field private String name; private (1) _float__...
Q:Could you fill in the blank。 class Employee{ // field private String name; private (1) _float__ salary; // constructor (2) ________________________________________ // method public (3) __String____ getName( ){ return name; } public float getSalary( ){ return Salary; } public (4) ________ compare( (5) _________________ { (6) ____________________________________ } }// class Employee public class EmployeeUI{ public static void main(String[ ] args){ Employee e1 = new Employee(“William”); Employee e2 = new Employee(“Rchard”); if(Employee.compare(e1, e2)) System.out.println(“same employee”); else System.out.println(“different employee”); } }//class EmployeeUI
TestQueue.java Design a class named Queue for storing integers. Like a stack, a queue holds elements....
TestQueue.java Design a class named Queue for storing integers. Like a stack, a queue holds elements. But in a queue, the elements are retrieved in a first-in first-out fashion. The class contains: An int[] data field named elements that stores the int values in the queue. A data field named size that stores the number of elements in the queue. A constructor that creates a Queue object with default capacity 8. The method enqueue(int v) that adds v into the...
c++ Design a class named Account that contains (keep the data fields private): a) An int...
c++ Design a class named Account that contains (keep the data fields private): a) An int data field named id for the account. b) A double data field named balance for the account. c) A double data field named annualInterestRate that stores the current interest rate. d) A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. e) The accessor and mutator functions for id, balance, and annualInterestRate. f) A function named getMonthlyInterestRate() that...
Create an interface named Turner, with a single method called turn(). Then create 4 classes: 1-...
Create an interface named Turner, with a single method called turn(). Then create 4 classes: 1- Leaf: that implements turn(), which changes the color of the Leaf object and returns true. If for any reason it is unable to change color, it should return false (you can come up with a reason for failure). The new color can be determined at random. 2- Document: that implements turn(), which changes the page on the document to the next page and returns...
C++ Do not use constructors Create a class named Coord in C++ Class has 3 private...
C++ Do not use constructors Create a class named Coord in C++ Class has 3 private data items               int xCoord;               int yCoord;               int zCoord; write the setters and getters. They should be inline functions               void setXCoord(int)             void setYCoord(int)            void setZCoord(int)               int getXCoord()                     int getYCoord()                   int getZCoord() write a member function named void display() that displays the data items in the following format      blank line      xCoord is                          ????????      yCoord is                          ????????...
Shapes2D Write the following four classes to practice using an abstract class and polymorphism. Submit all...
Shapes2D Write the following four classes to practice using an abstract class and polymorphism. Submit all four classes. Shape2D class For this class, include just an abstract method name get2DArea() that returns a double. Rectangle2D class Make this class inherit from the Shape2D class. Have it store a length and a width as fields. Provide a constructor that takes two double arguments and uses them to set the fields. Note, the area of a rectangle is the length times the...
Create a class named MyTriangle that contains the following three methods: public static boolean isValid(double sidea,...
Create a class named MyTriangle that contains the following three methods: public static boolean isValid(double sidea, double sideb, double sidec) public static double area(double sidea, double sideb, double sidec) public static String triangletType(double a, double b, double c) The isValid method returns true if the sum of the two shorter sides is greater than the longest side. The lengths of the 3 sides of the triangle are sent to this method but you may NOT assume that they are sent...
Create a class named MyTriangle that contains the following three methods: public static boolean isValid(double sidea,...
Create a class named MyTriangle that contains the following three methods: public static boolean isValid(double sidea, double sideb, double sidec) public static double area(double sidea, double sideb, double sidec) public static String triangletType(double a, double b, double c) The isValid method returns true if the sum of the two shorter sides is greater than the longest side. The lengths of the 3 sides of the triangle are sent to this method but you may NOT assume that they are sent...