Pembuatan simulasi remote AC menggunakan konsep PBO dengan BlueJ
Class yang digunakan :
/**
* Class yang berisi algoritma dan logika simulasi
*
* @author Satria Ade Veda Karuniawan
* @version Version 1.0
*/
public class Process
{
private boolean isOn;
private int temp;
private int fanspeed;
private int swing;
private int mode;
//Default Value
public Process()
{
isOn = false;
temp = 23;
fanspeed = 1;
swing = 30;
mode = 1;
}
//Menekan tombol Power
public void PowerButtonPressed()
{
if(isOn)
{
isOn = false;
}
else
{
isOn = true;
}
}
//Menekan Up Temperature
public void UpButtonPressed()
{
if(temp < 28)
{
temp++;
}
}
//Menekan Down Temperature
public void DownButtonPressed()
{
if(temp > 18)
{
temp--;
}
}
//Menekan Tombol Fan
public void FanButtonPressed()
{
if(fanspeed != 4)
{
fanspeed++;
}
else
{
fanspeed = 1;
}
}
//Menekan Tombol Swing
public void SwingButtonPressed()
{
if(swing != 90)
{
swing+=30;
}
else
{
swing = 30;
}
}
//Menekan Tombol Mode
public void ModeButtonPressed()
{
if(mode < 3)
{
mode++;
}
else
{
mode = 1;
}
}
//Fungsi-Fungsi di bawah untuk mendapatkan value dari tiap variable
public boolean GetPower()
{
return isOn;
}
public int GetTemp()
{
return temp;
}
public int GetFan()
{
return fanspeed;
}
public int GetSwing()
{
return swing;
}
public int GetMode()
{
return mode;
}
}
/**
* Class yang berisi estetika untuk display output
*
* @author Satria Ade Veda Karuniawan
* @version Version 1.0
*/
public class Display
{
//Display Temperature
//Pallet ░▒▓█
public void PrintNumber(int temp)
{
switch(temp)
{
case 18:
System.out.println("▓ ░░░░█ █████");
System.out.println("▓ ░░░░█ █░░░█");
System.out.println("▓ ░░░░█ █████");
System.out.println("▓ ░░░░█ █░░░█");
System.out.println("▓ ░░░░█ █████");
break;
case 19:
System.out.println("▓ ░░░░█ █████");
System.out.println("▓ ░░░░█ █░░░█");
System.out.println("▓ ░░░░█ █████");
System.out.println("▓ ░░░░█ ░░░░█");
System.out.println("▓ ░░░░█ █████");
break;
case 20:
System.out.println("▓ █████ █████");
System.out.println("▓ ░░░░█ █░░░█");
System.out.println("▓ █████ █░░░█");
System.out.println("▓ █░░░░ █░░░█");
System.out.println("▓ █████ █████");
break;
case 21:
System.out.println("▓ █████ ░░░░█");
System.out.println("▓ ░░░░█ ░░░░█");
System.out.println("▓ █████ ░░░░█");
System.out.println("▓ █░░░░ ░░░░█");
System.out.println("▓ █████ ░░░░█");
break;
case 22:
System.out.println("▓ █████ █████");
System.out.println("▓ ░░░░█ ░░░░█");
System.out.println("▓ █████ █████");
System.out.println("▓ █░░░░ █░░░░");
System.out.println("▓ █████ █████");
break;
case 23:
System.out.println("▓ █████ █████");
System.out.println("▓ ░░░░█ ░░░░█");
System.out.println("▓ █████ █████");
System.out.println("▓ █░░░░ ░░░░█");
System.out.println("▓ █████ █████");
break;
case 24:
System.out.println("▓ █████ █░░░█");
System.out.println("▓ ░░░░█ █░░░█");
System.out.println("▓ █████ █████");
System.out.println("▓ █░░░░ ░░░░█");
System.out.println("▓ █████ ░░░░█");
break;
case 25:
System.out.println("▓ █████ █████");
System.out.println("▓ ░░░░█ █░░░░");
System.out.println("▓ █████ █████");
System.out.println("▓ █░░░░ ░░░░█");
System.out.println("▓ █████ █████");
break;
case 26:
System.out.println("▓ █████ █████");
System.out.println("▓ ░░░░█ █░░░░");
System.out.println("▓ █████ █████");
System.out.println("▓ █░░░░ █░░░█");
System.out.println("▓ █████ █████");
break;
case 27:
System.out.println("▓ █████ █████");
System.out.println("▓ ░░░░█ ░░░░█");
System.out.println("▓ █████ ░░░░█");
System.out.println("▓ █░░░░ ░░░░█");
System.out.println("▓ █████ ░░░░█");
break;
case 28:
System.out.println("▓ █████ █████");
System.out.println("▓ ░░░░█ █░░░█");
System.out.println("▓ █████ █████");
System.out.println("▓ █░░░░ █░░░█");
System.out.println("▓ █████ █████");
break;
}
}
//Menu
public void PrintInfo(int fan, int swing, int mode)
{
System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
System.out.println("FAN SPEED");
switch(fan)
{
case 1:
System.out.println("████");
System.out.println("████");
System.out.println("████");
break;
case 2:
System.out.println("████████");
System.out.println("████████");
System.out.println("████████");
break;
case 3:
System.out.println("████████████");
System.out.println("████████████");
System.out.println("████████████");
break;
case 4:
System.out.println("████████████████");
System.out.println("████████████████");
System.out.println("████████████████");
break;
}
System.out.println("");
System.out.println("SWING");
System.out.println(swing + " Degrees");
System.out.println("");
switch(mode)
{
case 1:
System.out.println("COOL MODE");
break;
case 2:
System.out.println("DRY MODE");
break;
case 3:
System.out.println("POWERSAVER MODE");
break;
}
System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
}
}
Class yang digunakan :
- Main Class : Class utama yang berfungsi sebagai connector antara Process Class dengan Display Class.
- Process Class : Process Class menghandle seluruh algoritma untuk simulasi remote AC seperti saat tombol remote AC ditekan. Contoh : Menaikkan temperatur, Mengubah mode, dll.
- Display Class : Display Class menghandle seluruh komponen yang bertindak sebagai informasi yang nantinya akan dioutput ke console.
Workspace dari BlueJ
Source code Main Class
import java.util.Scanner;
/**
* Sebagai connector Process dan Display
*
* @author Satria Ade Veda Karuniawan
* @version Version 1.0
*/
public class Main
{
public static Process pobj = new Process();
public static Display dobj = new Display();
public static void main(String args[])
{
Scanner reader = new Scanner(System.in);
System.out.println("Nyalakan Remote AC? (Y/N)");
//Input Yes or No
char Input = reader.next().charAt(0);
while(Input != 'Y' && Input != 'N')
{
System.out.print('\u000C');
System.out.println("Error");
System.out.println("Nyalakan Remote AC? (Y/N)");
Input = reader.next().charAt(0);
}
//Jika Input Yes
if(Input == 'Y')
{
int Choice;
do
{
System.out.print('\u000C'); // CLS
dobj.PrintNumber(pobj.GetTemp());
dobj.PrintInfo(pobj.GetFan(), pobj.GetSwing(), pobj.GetMode());
MenuUtama();
Choice = reader.nextInt();
switch(Choice)
{
case 2:
pobj.UpButtonPressed();
break;
case 3:
pobj.DownButtonPressed();
break;
case 4:
pobj.FanButtonPressed();
break;
case 5:
pobj.SwingButtonPressed();
break;
case 6:
pobj.ModeButtonPressed();
break;
}
}
while(Choice != 1);
}
System.out.print('\u000C');
System.out.print("TURNED OFF");
return;
}
public static void MenuUtama()
{
System.out.println("1. Turn Off");
System.out.println("2. Increase Temperature");
System.out.println("3. Decrease Temperature");
System.out.println("4. Fan");
System.out.println("5. Swing");
System.out.println("6. Mode");
}
}
/**
* Sebagai connector Process dan Display
*
* @author Satria Ade Veda Karuniawan
* @version Version 1.0
*/
public class Main
{
public static Process pobj = new Process();
public static Display dobj = new Display();
public static void main(String args[])
{
Scanner reader = new Scanner(System.in);
System.out.println("Nyalakan Remote AC? (Y/N)");
//Input Yes or No
char Input = reader.next().charAt(0);
while(Input != 'Y' && Input != 'N')
{
System.out.print('\u000C');
System.out.println("Error");
System.out.println("Nyalakan Remote AC? (Y/N)");
Input = reader.next().charAt(0);
}
//Jika Input Yes
if(Input == 'Y')
{
int Choice;
do
{
System.out.print('\u000C'); // CLS
dobj.PrintNumber(pobj.GetTemp());
dobj.PrintInfo(pobj.GetFan(), pobj.GetSwing(), pobj.GetMode());
MenuUtama();
Choice = reader.nextInt();
switch(Choice)
{
case 2:
pobj.UpButtonPressed();
break;
case 3:
pobj.DownButtonPressed();
break;
case 4:
pobj.FanButtonPressed();
break;
case 5:
pobj.SwingButtonPressed();
break;
case 6:
pobj.ModeButtonPressed();
break;
}
}
while(Choice != 1);
}
System.out.print('\u000C');
System.out.print("TURNED OFF");
return;
}
public static void MenuUtama()
{
System.out.println("1. Turn Off");
System.out.println("2. Increase Temperature");
System.out.println("3. Decrease Temperature");
System.out.println("4. Fan");
System.out.println("5. Swing");
System.out.println("6. Mode");
}
}
Source code Process Class
/**
* Class yang berisi algoritma dan logika simulasi
*
* @author Satria Ade Veda Karuniawan
* @version Version 1.0
*/
public class Process
{
private boolean isOn;
private int temp;
private int fanspeed;
private int swing;
private int mode;
//Default Value
public Process()
{
isOn = false;
temp = 23;
fanspeed = 1;
swing = 30;
mode = 1;
}
//Menekan tombol Power
public void PowerButtonPressed()
{
if(isOn)
{
isOn = false;
}
else
{
isOn = true;
}
}
//Menekan Up Temperature
public void UpButtonPressed()
{
if(temp < 28)
{
temp++;
}
}
//Menekan Down Temperature
public void DownButtonPressed()
{
if(temp > 18)
{
temp--;
}
}
//Menekan Tombol Fan
public void FanButtonPressed()
{
if(fanspeed != 4)
{
fanspeed++;
}
else
{
fanspeed = 1;
}
}
//Menekan Tombol Swing
public void SwingButtonPressed()
{
if(swing != 90)
{
swing+=30;
}
else
{
swing = 30;
}
}
//Menekan Tombol Mode
public void ModeButtonPressed()
{
if(mode < 3)
{
mode++;
}
else
{
mode = 1;
}
}
//Fungsi-Fungsi di bawah untuk mendapatkan value dari tiap variable
public boolean GetPower()
{
return isOn;
}
public int GetTemp()
{
return temp;
}
public int GetFan()
{
return fanspeed;
}
public int GetSwing()
{
return swing;
}
public int GetMode()
{
return mode;
}
}
Source code Display Class
/**
* Class yang berisi estetika untuk display output
*
* @author Satria Ade Veda Karuniawan
* @version Version 1.0
*/
public class Display
{
//Display Temperature
//Pallet ░▒▓█
public void PrintNumber(int temp)
{
switch(temp)
{
case 18:
System.out.println("▓ ░░░░█ █████");
System.out.println("▓ ░░░░█ █░░░█");
System.out.println("▓ ░░░░█ █████");
System.out.println("▓ ░░░░█ █░░░█");
System.out.println("▓ ░░░░█ █████");
break;
case 19:
System.out.println("▓ ░░░░█ █████");
System.out.println("▓ ░░░░█ █░░░█");
System.out.println("▓ ░░░░█ █████");
System.out.println("▓ ░░░░█ ░░░░█");
System.out.println("▓ ░░░░█ █████");
break;
case 20:
System.out.println("▓ █████ █████");
System.out.println("▓ ░░░░█ █░░░█");
System.out.println("▓ █████ █░░░█");
System.out.println("▓ █░░░░ █░░░█");
System.out.println("▓ █████ █████");
break;
case 21:
System.out.println("▓ █████ ░░░░█");
System.out.println("▓ ░░░░█ ░░░░█");
System.out.println("▓ █████ ░░░░█");
System.out.println("▓ █░░░░ ░░░░█");
System.out.println("▓ █████ ░░░░█");
break;
case 22:
System.out.println("▓ █████ █████");
System.out.println("▓ ░░░░█ ░░░░█");
System.out.println("▓ █████ █████");
System.out.println("▓ █░░░░ █░░░░");
System.out.println("▓ █████ █████");
break;
case 23:
System.out.println("▓ █████ █████");
System.out.println("▓ ░░░░█ ░░░░█");
System.out.println("▓ █████ █████");
System.out.println("▓ █░░░░ ░░░░█");
System.out.println("▓ █████ █████");
break;
case 24:
System.out.println("▓ █████ █░░░█");
System.out.println("▓ ░░░░█ █░░░█");
System.out.println("▓ █████ █████");
System.out.println("▓ █░░░░ ░░░░█");
System.out.println("▓ █████ ░░░░█");
break;
case 25:
System.out.println("▓ █████ █████");
System.out.println("▓ ░░░░█ █░░░░");
System.out.println("▓ █████ █████");
System.out.println("▓ █░░░░ ░░░░█");
System.out.println("▓ █████ █████");
break;
case 26:
System.out.println("▓ █████ █████");
System.out.println("▓ ░░░░█ █░░░░");
System.out.println("▓ █████ █████");
System.out.println("▓ █░░░░ █░░░█");
System.out.println("▓ █████ █████");
break;
case 27:
System.out.println("▓ █████ █████");
System.out.println("▓ ░░░░█ ░░░░█");
System.out.println("▓ █████ ░░░░█");
System.out.println("▓ █░░░░ ░░░░█");
System.out.println("▓ █████ ░░░░█");
break;
case 28:
System.out.println("▓ █████ █████");
System.out.println("▓ ░░░░█ █░░░█");
System.out.println("▓ █████ █████");
System.out.println("▓ █░░░░ █░░░█");
System.out.println("▓ █████ █████");
break;
}
}
//Menu
public void PrintInfo(int fan, int swing, int mode)
{
System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
System.out.println("FAN SPEED");
switch(fan)
{
case 1:
System.out.println("████");
System.out.println("████");
System.out.println("████");
break;
case 2:
System.out.println("████████");
System.out.println("████████");
System.out.println("████████");
break;
case 3:
System.out.println("████████████");
System.out.println("████████████");
System.out.println("████████████");
break;
case 4:
System.out.println("████████████████");
System.out.println("████████████████");
System.out.println("████████████████");
break;
}
System.out.println("");
System.out.println("SWING");
System.out.println(swing + " Degrees");
System.out.println("");
switch(mode)
{
case 1:
System.out.println("COOL MODE");
break;
case 2:
System.out.println("DRY MODE");
break;
case 3:
System.out.println("POWERSAVER MODE");
break;
}
System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
}
}
SIMULASI
- Saat program dijalankan
- Saat Y diinputkan
- Saat angka 1 diinputkan
- Saat angka 2 diinputkan
- Saat angka 3 diinputkan
- Saat angka 4 diinputkan
- Saat angka 5 diinputkan
- Saat angka 6 diinputkan
Comments
Post a Comment