Tugas Remote AC - PBO A
Tugas PBO A kali ini yaitu membuat simulasi pada remote AC.
Nama : Ifta Jihan Nabila
NRP : 05111740000034
Kali ini saya membuat remote AC menggunakan Java pada BlueJ. Saya membuat 2 class yaitu Main dan Remote. Untuk menu yang saya tampilkan yaitu:
1. Temperature (menaikkan atau menurunkan suhu)
2. Mode (Mengubah mode AC)
3. Fan Speed (Mengubah kecepatan kipas AC)
4. Air Swing (Mengubah swing AC)
5. Turn Off (Mematikan AC)
Berikut ini adalah source codenya:
- Main
/**
* Remote AC
* @author Ifta Jihan N (05111740000034)
* PBO A
*/
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
int suhuawal;
int modeac, fanac, swingac;
boolean c = true;
System.out.print('\u000C');
System.out.println("********************************");
System.out.println("========AC Remote Control=======");
System.out.println("********************************");
System.out.print("Enter Temperature (16-30°C): ");
suhuawal = scan.nextInt();
System.out.print("\n");
Remote remoteac = new Remote(suhuawal);
modeac = remoteac.mode;
fanac = remoteac.fan;
swingac = remoteac.swing;
while(c)
{
System.out.println("********************************");
System.out.println("========AC Remote Control=======");
System.out.println("********************************");
System.out.println("Temperature : "+suhuawal+" °C");
remoteac.currmode(modeac);
remoteac.fanspeed(fanac);
remoteac.swing(swingac);
System.out.println("--------------------------------");
System.out.println("Menu:");
System.out.println("1. Temperature");
System.out.println("2. Mode");
System.out.println("3. Fan Speed");
System.out.println("4. Air Swing");
System.out.println("5. Turn Off");
System.out.println("--------------------------------");
int menu = scan.nextInt();
System.out.print('\u000C');
switch(menu)
{
case 1:
System.out.println("********************************");
System.out.println("========AC Remote Control=======");
System.out.println("********************************");
System.out.println("Temperature : "+suhuawal+" °C");
remoteac.currmode(modeac);
remoteac.fanspeed(fanac);
remoteac.swing(swingac);
System.out.println("--------------------------------");
remoteac.suhu(suhuawal);
int csuhu = scan.nextInt();
System.out.print('\u000C');
int suhu2;
if(csuhu==1)
{
suhu2 = remoteac.upsuhu(suhuawal);
suhuawal = suhu2;
}
else if(csuhu==2)
{
suhu2 = remoteac.downsuhu(suhuawal);
suhuawal = suhu2;
}
System.out.print('\u000C');
break;
case 2:
System.out.println("********************************");
System.out.println("========AC Remote Control=======");
System.out.println("********************************");
System.out.println("Temperature : "+suhuawal+" °C");
remoteac.currmode(modeac);
remoteac.fanspeed(fanac);
remoteac.swing(swingac);
System.out.println("--------------------------------");
remoteac.mode(modeac);
int choosemode = scan.nextInt();
int modenow = remoteac.changemode(choosemode);
modeac = modenow;
System.out.print('\u000C');
break;
case 3:
System.out.println("********************************");
System.out.println("========AC Remote Control=======");
System.out.println("********************************");
System.out.println("Temperature : "+suhuawal+" °C");
remoteac.currmode(modeac);
remoteac.fanspeed(fanac);
remoteac.swing(swingac);
System.out.println("--------------------------------");
remoteac.fan(fanac);
int choosefan = scan.nextInt();
int fannow = remoteac.changefan(choosefan);
fanac = fannow;
System.out.print('\u000C');
break;
case 4:
System.out.println("********************************");
System.out.println("========AC Remote Control=======");
System.out.println("********************************");
System.out.println("Temperature : "+suhuawal+" °C");
remoteac.currmode(modeac);
remoteac.fanspeed(fanac);
remoteac.swing(swingac);
System.out.println("--------------------------------");
remoteac.airswing(swingac);
int chooseas = scan.nextInt();
int swnow = remoteac.changeswing(chooseas);
swingac = swnow;
System.out.print('\u000C');
break;
case 5:
System.out.print('\u000C');
c = false;
System.out.print("AC has been turned off");
break;
}
}
}
}
- Remote
/**
* Remote AC
* @author Ifta Jihan N (05111740000034)
* PBO A
*/
public class Remote
{
public int suhu;
public int mode;
public int fan;
public int swing;
public Remote(int suhuawal)
{
suhu = suhuawal;
mode = 1;
fan = 1;
swing = 1;
}
public void suhu(int cursuhu)
{
System.out.println("Temperature : "+cursuhu+" °C");
System.out.println("1. ▲");
System.out.println("2. ▼");
}
public int upsuhu(int up)
{
up++;
return(up);
}
public int downsuhu(int down)
{
down--;
return(down);
}
public void currmode(int curmode)
{
if(curmode==1)
{
System.out.println("Mode : Auto");
}
else if(curmode==2)
{
System.out.println("Mode : Cold");
}
else if(curmode==3)
{
System.out.println("Mode : Dry");
}
}
public void mode(int curmode)
{
currmode(curmode);
System.out.println("Change Mode :");
System.out.println("1. Auto");
System.out.println("2. Cold");
System.out.println("3. Dry");
}
public int changemode(int pilihmode)
{
if(pilihmode == 1)
{
mode = 1;
System.out.println("Mode : Auto");
}
else if(pilihmode == 2)
{
mode = 2;
System.out.println("Mode : Cold");
}
else if(pilihmode == 3)
{
mode = 3;
System.out.println("Mode : Dry");
}
return(mode);
}
public void fanspeed(int curfan)
{
if(curfan==1)
{
System.out.println("Fan Speed : Auto");
}
else if(curfan==2)
{
System.out.println("Fan Speed : █");
}
else if(curfan==3)
{
System.out.println("Fan Speed : ██");
}
else if(curfan==4)
{
System.out.println("Fan Speed : ███");
}
}
public void fan(int speed)
{
fanspeed(speed);
System.out.println("Change Fan Speed :");
System.out.println("1. Fan Speed : Auto");
System.out.println("2. Fan Speed : █");
System.out.println("3. Fan Speed : ██");
System.out.println("4. Fan Speed : ███");
}
public int changefan(int speed2)
{
if(speed2==1)
{
fan = 1;
System.out.println("Fan Speed : Auto");
}
else if(speed2==2)
{
fan = 2;
System.out.println("Fan Speed : █");
}
else if(speed2==3)
{
fan = 3;
System.out.println("Fan Speed : ██");
}
else if(speed2==4)
{
fan = 4;
System.out.println("Fan Speed : ███");
}
return(fan);
}
public void swing(int sw)
{
if(sw==1)
{
System.out.println("Air Swing : On");
}
else if(sw==2)
{
System.out.println("Air Swing : Off");
}
}
public void airswing(int swing2)
{
swing(swing2);
System.out.println("Change Air Swing :");
System.out.println("1. On");
System.out.println("2. Off");
}
public int changeswing(int pilihsw)
{
if(pilihsw == 1)
{
swing = 1;
System.out.println("Air Swing : On");
}
else if(pilihsw == 2)
{
swing = 2;
System.out.println("Air Swing : Off");
}
return(swing);
}
}
Dan ini adalah hasilnya:
Hasil ketika saya mengubah suhu
Hasil ketika saya mengubah mode
Hasil ketika saya mengubah fan speed
Hasil ketika saya mengubah air swing
Hasil ketika saya mematikan AC
Terima kasih.
Comments
Post a Comment