Question

In: Computer Science

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. Fill in the blank to complete the turnOff method.

public void turnOff() {
    ______________________
}

Solutions

Expert Solution

The given requirement is to fill in the blank to complete the method turnOff , So the C++ code filling the blank is below.

Note: Since the question did not specify the code fill should be in C++ or Java. i have provide both codes as screenshots below after this code section .

 void turnOff()
    {
        on =false;
        cout << "AirConditioner is set off. So the variable  on is " <<  on;
    }

Full code of C++ for your understanding below



#include <iostream>

using namespace std;
class AirConditioner
{
    private:
    
             bool on;
    public:
    void turnOff()
    {
        on =false;
        cout << "AirConditioner is set off. So the variable  on is " <<  on;
    }
    
};
int main()
{
    AirConditioner  obj;
    obj.turnOff();

    return 0;
}

Please find the screen shot of full code in C++ and output below

Please find the full code in java and output below for your understanding

public class Main
{
static class AirConditioner
{
   
   private static boolean on;
   
   public static void turnOff()
    {  
       on=false;
        System.out.println(" AirConditioner is set off. So the variable  on is "+ on);
    }
    
};

        public static void main(String[] args)
        {
            
            AirConditioner obj = new AirConditioner();
                obj.turnOff();
        }
}

Please find the screen shot of full code and output in java below


Related Solutions

Design a class named Account that contains: A private int data field named id for the...
Design a class named Account that contains: A private int data field named id for the account. A private double data field named balance for the account. A private double data field named annualInterestRate that stores the current interest rate. A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. The accessor and mutator methods for id, balance, and annualInterestRate. A method named getMonthlyInterestRate() that returns the monthly interest rate. A method named withdraw(amount)...
Design a class named Account that contains: A private String data field named accountNumber for the...
Design a class named Account that contains: A private String data field named accountNumber for the account (default AC000). A private double data field named balance for the account (default 0). A private double data field named annualIntRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default account. A constructor...
Design a class named BankAccount that contains: A private int data field named id for the...
Design a class named BankAccount that contains: A private int data field named id for the account. A private double data field named balance for the account. A constructor that creates an account with the specified id and initial balance. A getBalance() method that shows the balance. A method named withdraw that withdraws a specified amount from the account. Create a subclass of the BankAccount class named ChequingAccount. An overdraftlimit to be 1000 for ChequingAccount . Test your ChequingAccount class...
Design a class named Account that contains: ■ A private int data field named id for...
Design a class named Account that contains: ■ A private int data field named id for the account (default 0). ■ A private double data field named balance for the account (default 0). ■ A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. ■ A private Date data field named dateCreated that stores the date when the account was created. ■ A no-arg constructor that creates...
Java - Design a class named Account that contains: A private String data field named accountNumber...
Java - Design a class named Account that contains: A private String data field named accountNumber for the account (default AC000). A private double data field named balance for the account (default 0). A private double data field named annualIntRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default account....
Private int data field named id for the account A private double data field named balance...
Private int data field named id for the account A private double data field named balance for the account Private double data field named annualInterestRate that stores the current interest rate Assume all accounts have the same rate Private date data field named date Created that stores the date when the account was created No arg constructor that creates an account with the specified id and initial balance The get and set methods for id balance and annual Interest Rate...
a)Adoubledata field(private)named realfor real part of a complex number. b)Adoubledata field(private)named imgfor imaginarypart of a complex...
a)Adoubledata field(private)named realfor real part of a complex number. b)Adoubledata field(private)named imgfor imaginarypart of a complex number. c)A no-arg constructor that creates a default complex number with real 0and img 0. d)Auser-defined constructorthat creates a complex number with given 2 numbers. e)The accessor and mutator functions for realand img. f)A constant function named addition(Complex&comp1, Complex&comp2) that returns the sum of two givencomplex numbers. g)Aconstantfunction named subtraction(Complex&comp1, Complex&comp2) that returns the subtractionof two givencomplex numbers. h)A constant function named multiplication(Complex&comp1, Complex&comp2)...
The Account class Create a class named Account, which has the following private properties:
in java The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber (), getBalance (), setBalan newBalance). There is no setNumber () once an account is created, its account number cannot change. Now implement these methods: void deposit (double amount) and void withdraw (double amount). For both these methods, if the amount is less than...
The Account class Create a class named Account , which has the following private properties:
 The Account class Create a class named Account , which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNunber(), getBalance(), setBalance (double newBalance) . There is no setNunber() - once an account is created, its account number cannot change. Now implement these methods: void deposit (double anount) and void withdraw(double anount). For both these methods, if the amount is less than zero,...
In the following class: public class Truth { private boolean yes_no; ... } Create constructor, setter...
In the following class: public class Truth { private boolean yes_no; ... } Create constructor, setter and getter methods, and toString method.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT