Hey guys! In this post I'm going to show you how to make an AC Remote using BlueJ.
I'm going to use 2 classes, which are:
I'm going to use 2 classes, which are:
- Main
- ACRemote
Main
/*
* Main function for the AC Remote
*
* Elkana Hans Widersen
* 05111740000127
* 23 September 2018
*/
import java.util.Scanner;
public class Main{
public static void main(String args[]){
int menu;
Scanner input = new Scanner(System.in);
//Creates the remote
ACRemote remote = new ACRemote();
while(true){
//displays the remote interface every loop
remote.display();
//scans for menu number
menu = input.nextInt();
switch(menu){
//changes the temperature
case 1: remote.TempUp(); break;
case 2: remote.TempDown(); break;
//sets the AC swing mode
case 3: remote.getSwing(); break;
//terminates when the AC turned off
case 4: System.exit(0); break;
}
}
}
}
ACRemote
/*
* AC Remote Function
*
* Elkana Hans Widersen
* 05111740000127
* 23 September 2018
*/
public class ACRemote{
private int temp;
private String swing;
//AC Remote Declaration
public ACRemote(){
temp = 24;
swing = "OFF";
}
//Sets Swing Mode
public void getSwing(){
if(swing == "OFF") swing = "ON ";
else swing = "OFF";
}
//Decrease temperature
public void TempDown(){
if(temp == 18) temp = 18;
else temp--;
}
//Increase temperature
public void TempUp(){
if(temp == 30) temp = 30;
else temp++;
}
//Displays the remote interface
public void display(){
System.out.println("|-------------------|");
System.out.println("| TOSHIBA |");
System.out.println("| Air Conditioner |");
System.out.println("|-------------------|");
System.out.println("| " + temp + " |");
System.out.println("|-------------------|");
System.out.println("| SWING = " + swing + " |");
System.out.println("|-------------------|");
System.out.println("| 1. ^ 2. v |");
System.out.println("| 3. Swing ON/OFF |");
System.out.println("| 4. AC Power OFF |");
System.out.println("|-------------------|\n");
}
}
Thank you and see you next time!
Komentar
Posting Komentar