1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NeX [460]
3 years ago
10

Suppose there is a class AirConditioner. The class supports the following behaviors: turning the air conditioner on and off. The

following methods are provided for these behaviors: turn_on and turn_off. Both methods accept no arguments and return no value.
"There is a reference variable my_ac to an object of this class, which has already been created. There is also a variable status, which has already been initialized which refers to a bool. Invoke a method of this object using the reference variable, asking the object to tell whether the air conditioner is on or off, and store the result in status."
Computers and Technology
1 answer:
Ksenya-84 [330]3 years ago
5 0

Answer:

Firstly, create an AirConditioner class inside a file named as AirConditioner.java. This is important to make sure the class name match with the file name.

  1. public class AirConditioner {
  2.    private boolean status = false;
  3.    public void turn_on()
  4.    {
  5.        this.status = true;
  6.    }
  7.    public void turn_off()
  8.    {
  9.        this.status = false;
  10.    }
  11.    public boolean getStatus()
  12.    {
  13.        return this.status;
  14.    }
  15. }

Next, create another file named as Main.java. This is where we are going to include a Main method to create an object of AirConditioner class and get the air conditioner status. The codes are as follows:

  1. public class Main {
  2.    public static void main(String[] args) {
  3.        AirConditioner my_ac= new AirConditioner();
  4.        boolean status;
  5.        my_ac.turn_on();
  6.        status = my_ac.getStatus();
  7.        System.out.println(status);
  8.    }
  9. }

Explanation:

The codes presented above are written based on the question requirements.

<u>AirConditioner.java</u>

Line 1:

  • Create an AirConditioner  class

Line 3:

  • A property status is defined. This is important to track the status of an AirConditioner object.

Line 5 -8 and Line 10 -13:

  • Create two required methods turn_on() and turn_off(). Both of them accept no arguments and return no value.
  • The only job done by this two methods is to change the status property to either true (on) or false (off).

Line 15 - 18:

  • The getStatus() method is to return the current status of the AirConditioner object to the Main method in main.java.

<u>Main.java</u>

Line 5-6:

  • Within the Main method, create an object of AirConditioner and assign it to a reference variable, my_ac
  • Create the status variable as a boolean variable.

Line 8:

  • Use reference variable my_ac to invoke turn_on() method to change the status of the AirConditioner object to true
  • Use the same reference variable my_ac to invoke getStatus() method to get the current satus of the AirConditioner object and assign it to the status variable.

Line 11:

  • Print the status of AirConditioner Object in terminal
You might be interested in
Write a short note on Computer<br>impact on<br> our society?​
Vesna [10]

well not a note but here are some few points

Explanation:

1 Computers can have the huge impact on employment of people like job and other stuff.

2 lots of human can be jobless or unemployed

3 it can cuz impact on the health of peoples

4 it also can make us lazy and and lack of self knowledge

8 0
3 years ago
Read 2 more answers
A photograph with more yellows has which mood
just olya [345]

Answer:

Yellow reflects most of the light and thus draws lots of attention; too bright a shade will leave you irritated. Prolonged exposure can also have a tiring effect. It is best used in down-tones; as background for white articles/figures. Green is the color of tranquility and vibrant.

Explanation:

6 0
3 years ago
Read 2 more answers
Html version ____ added support for style sheets to give web designers greater control over page layout and appearance.
galina1969 [7]
I believe it was HTML4.




____________________
3 0
3 years ago
Differentiate between inherited trait and acquired trait​
miskamm [114]

Answer: Inherited trait is something you already have and acquired is something that you learn or achieve.

Explanation:

8 0
3 years ago
Questions 6 - 9 Refer to the following code: public class WhatsIt { private int[] values; private double average; public WhatsIt
gavmur [86]

Answer:

class WhatsIt

{

private static int [] values;

private double average;

public Double Average=average;

public WhatsIt () {values = new int [10]; findAvg(); }

public WhatsIt (int [] n) {values = n; findAvg(); }

public static void findAvg ()

{double sum = 0;

for (int i = 0; i < values.length; i++)

{sum += values[i]; }

average = 1.0 * sum / values.length;

System.out.println(Average);

System.out.println(average);

}

public static String ToString()

{

   System.out.println(average); System.out.println(values.length);

   return "Average: " + average + " Length: " + values.length;

}

public static void main(String[] args)  

{

    //WhatsIt();

    //ToString();

    findAvg();

}

}

The findAvg() calculates the average.

The reference to average is defined as below:

public double Average=average;

And when we call findAvg average is initialized, and Average is also initialized, which we can check through println statement.

Explanation:

Please check the answer section.

4 0
3 years ago
Other questions:
  • "A Windows laptop is being used by a teacher in an outdoor (but protected by an overhang) setting. What setting would ensure tha
    5·1 answer
  • What kind of digital certificate is typically used to ensure the authenticity of a web server to a client?
    7·1 answer
  • Does the Main Content (MC) of a web page include searchboxes?
    10·1 answer
  • Refer to the exhibit. The web servers WS_1 and WS_2 need to be accessed by external and internal users. For security reasons, th
    12·1 answer
  • What type of control repairs the effects of damage from an attack? Physical control Technical control Corrective control Logical
    5·1 answer
  • Create a dynamic array of 100 integer values named myNums. Use a pointer variable (like ptr) which points to this array. Use thi
    6·1 answer
  • Which function in Ecels tells how many numeric entries are there​
    7·2 answers
  • Select the correct answer.
    15·1 answer
  • Which engineer may design a GPS for a vehicle?
    15·1 answer
  • Question 22 of 25
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!