Tugas #PBOA-tugas 3 (Remote AC)
Class and Object
Remote AC
berikut ini adalah program untuk membuat simulasi remote AC. Remote AC ini memiliki fitur mengubah suhu, fan, dan mode. Sedangkan disini saya menggunakan dua class, yaitu remoteAC dan Main.
- remoteAC
- Main
/**
* Write a description of class ticketMachine here.
*
* @author (Nitama Nurlingga Yotifa)
* @version (20180922)
*/
public class remoteAC
{
private int suhu;
private int mode;
private int fan;
/**
* Constructor for objects of class ticketMachine
*/
public remoteAC(int suhuAC, int fanAC, int modeAC)
{
suhu = suhuAC;
mode = modeAC;
fan = fanAC;
}
//menampilkan suhu sekarang
public int getTemperature()
{
return suhu;
}
//menampilkan mode sekarang
public int getMode()
{
return mode;
}
//menampilkan fan sekarang
public int getFan()
{
return fan;
}
//menaikkan suhu AC
public int naikkanSuhu()
{
if (suhu == 30 )
{
return suhu;
}
else
{
suhu += 1;
return suhu;
}
}
//menurunkan suhu AC
public int turunkanSuhu()
{
if (suhu == 16)
{
return suhu;
}
else
{
suhu-= 1;
return suhu;
}
}
//mengganti mode AC
public int gantiMode()
{
if(mode==5)
{
mode = 1;
return mode;
}
else
{
mode+= 1;
return mode;
}
}
//mengganti tipe fan ke arah atas
public int naikkanFan()
{
if(fan == 3)
{
fan = 1;
return fan;
}
else
{
fan+= 1;
return fan;
}
}
//mengganti fan ke arah bawah
public int turunkanFan()
{
if(fan == 1)
{
fan = 3;
return fan;
}
else
{
fan-= 1;
return fan;
}
}
}
/**
* Write a description of class IntMain here.
*
* @author (Nitama Nurlingga Yotifa)
* @version (20180922)
*/
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
int suhuAC, modeAC, fanAC, tombol;
boolean power;
System.out.println("~~~~~~~~~~~~~~~~~~~Remote AC~~~~~~~~~~~~~~~~~~~");
System.out.println("Suhu sekarang (16-30 derejad celcius): ");
suhuAC = scan.nextInt();
System.out.println("Fan sekarang (Tipe 1-3): ");
fanAC = scan.nextInt();
System.out.println("Mode sekarang (1[cool] 2[dry] 3[fan] 4[heat] 5[auto]): ");
modeAC = scan.nextInt();
remoteAC LG = new remoteAC(suhuAC, fanAC, modeAC);
power = true;
while(power)
{
System.out.println("Pilihan Tombol: ");
System.out.println("1. Tampilkan suhu sekarang");
System.out.println("2. Tampilkan fan sekarang");
System.out.println("3. Tampilkan mode sekarang");
System.out.println("4. Naikkan suhu");
System.out.println("5. Turunkan suhu");
System.out.println("6. Naikkan fan");
System.out.println("7. Turunkan fan");
System.out.println("8. Ganti mode");
System.out.println("9. Matikan AC");
System.out.println("Tombol yang dipilih> ");
tombol = scan.nextInt();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
switch(tombol)
{
case 1:
System.out.println("Suhu: "+suhuAC+" derajad celcius");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
break;
case 2:
System.out.println("Fan: "+fanAC);
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
break;
case 3:
if(modeAC == 1)
{
System.out.println("Mode: cool");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
else if(modeAC == 2)
{
System.out.println("Mode: dry");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
else if(modeAC == 3)
{
System.out.println("Mode: fan");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
else if(modeAC == 4)
{
System.out.println("Mode: heat");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
else
{
System.out.println("auto");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
break;
case 4:
suhuAC = LG.naikkanSuhu();
System.out.println("Suhu: "+suhuAC+" derajad celcius");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
break;
case 5:
suhuAC = LG.turunkanSuhu();
System.out.println("Suhu: "+suhuAC+" derajad celcius");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
break;
case 6:
fanAC = LG.naikkanFan();
System.out.println("Fan: "+fanAC);
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
break;
case 7:
fanAC = LG.turunkanFan();
System.out.println("Fan: "+fanAC);
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
break;
case 8:
modeAC = LG.gantiMode();
if(modeAC == 1)
{
System.out.println("Mode: cool");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
else if(modeAC == 2)
{
System.out.println("Mode: dry");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
else if(modeAC == 3)
{
System.out.println("Mode: fan");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
else if(modeAC == 4)
{
System.out.println("Mode: heat");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
else
{
System.out.println("auto");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
break;
case 9:
System.out.println("AC mati");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
power = false;
break;
}
}
}
}
Untuk menjalankan program dapat dilakukan dengan langkah-langkah berikut :
- Klik kanan class main, pilih void main(String[]args). Lalu klik OK.
- Masukkan suhu sekarang, fan sekarang, dan mode sekarang sebagai kondisi AC saat ini.
- Lalu masukkan menu yang akan dipilih.
Disini memiliki sembilan pilihan menu yang dapat dipilh, yaitu :
- Tampilkan suhu sekarang
- Tampilkan fan sekarang
- Tampilkan mode sekarang
- Naikkan suhu
- Turunkan suhu
- Naikkan fan
- Turunkan fan
- Ganti mode
- Matikan AC
Komentar
Posting Komentar