In: Computer Science
Creat a program that is part of a control system for a house. Create two Boolean variables: doorUnLocked and lightOn. Set both to false. Create an int variable: currentTemp. Set the currentTemp value to 70 Create two more Boolean variables: heatOn and coolingOn. Set both of these values to false. Ask the user if they want to unlock the door, turn on the light and what value the temperature should be. If they want to unlock the door, set doorUnlocked to true. If they do not want to unlock the door, set the doorUnlocked value to false. If they want to turn on the light set lightOn to true. If they do not want to turn on the light set the lightOn to false. For the desired temperature value, if the desired value is the same as the currentTemp, do nothing. If the desired value is less than the currentTemp set coolingOn to true and heatOn to false. If the desired value is more than the currentTemp set heatOn to true and coolingOn to false. Display the state of the door (locked or unlocked), the state of the lights (on or off) and the desired temperature and the current temperature. Ask the user if they want to make changes. If they do, loop back and ask for all three values again. If no changes are desired, end the program.
Hi,
Program:
import java.util.Scanner;
//HCS class
public class HCS {
//main method
public static void main(String args[]) {
//variables declaration
boolean doorUnLocked = false;
boolean lightOn = false;
int currentTemp = 70;
boolean heatOn = false;
boolean coolingOn = false;
System.out.println("\n**** WELCOME TO HOUSE CONTROL SYSTEM ****");
Scanner sc = new
Scanner(System.in);
String ch = null;
do {
//get the input
from user
System.out.print("\nDo you want to unlock the door(y/n): ");
String status =
sc.next();
//checking
the conditions
if
(status.equalsIgnoreCase("y") ||
status.equalsIgnoreCase("yes"))
doorUnLocked = true;
else
doorUnLocked = false;
System.out.print("\nDo you want to turn on the ligh(y/n): ");
status =
sc.next();
if
(status.equalsIgnoreCase("y") ||
status.equalsIgnoreCase("yes"))
lightOn = true;
else
lightOn = false;
System.out.print("\nPlease enter your desired temperature:
");
int temp =
sc.nextInt();
//checking the
conditions
if (temp <
currentTemp) {
coolingOn = true;
heatOn = false;
} else if (temp
> currentTemp) {
coolingOn = false;
heatOn = true;
} else {
coolingOn = false;
heatOn = false;
}
//displaying
values
System.out.println("\nIs door unLocked: " + doorUnLocked);
System.out.println("Is light on: " + lightOn);
System.out.println("Current temparature is: " + currentTemp);
System.out.println("Desired temparature is: " + temp);
System.out.println("Is Heat on: " + heatOn);
System.out.println("Is Cool on: " + coolingOn);
System.out.print("\nDo you want make more changes(y/n): ");
ch =
sc.next();
} while (ch.equalsIgnoreCase("y"));
}
}
Output Screenshots: