Remote TV
/**
* RemotTV
*
* @author (Ismail)
* @version (23/09/2018)
*/
public class RemotTV
{
private int channel;
private int volume;
public RemotTV()
{
channel = 0;
volume = 50;
}
public void cekTV()
{
System.out.println("##########################");
System.out.println("# Anda sedang menonton #");
if(channel > 0 && channel <8)
{
switch(channel)
{
case 1:
System.out.println("#\tSCTV");
break;
case 2:
System.out.println("#\tINDOSIAR");
break;
case 3:
System.out.println("#\tRCTI");
break;
case 4:
System.out.println("#\tGLOBAL TV");
break;
case 5:
System.out.println("#\tTRANS TV");
break;
case 6:
System.out.println("#\tANTV");
break;
case 7:
System.out.println("#\tNET TV");
break;
}
}
else
{
System.out.println("# Channel tidak tersedia");
}
System.out.println("# Selamat Menyaksikan #");
System.out.println("##########################");
}
public int gantichannel(int nomor)
{
return channel=nomor;
}
public int cekvolume()
{
return volume;
}
public int tambahvolume()
{
return volume+=1;
}
public int kurangivolume()
{
return volume-=1;
}
}
Main
/**
* Main.
*
* @author (Ismail)
* @version (23/09/2018)
*/
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
int menu, channel, volume;
RemotTV remot = new RemotTV();
System.out.println("1. Nonton TV");
System.out.println("2. Ganti Channel");
System.out.println("3. Cek Volume");
System.out.println("4. Tambah Volume");
System.out.println("5. Kurangi Volume");
System.out.println("6. Matikan TV");
int tipe=1;
while(tipe == 1)
{
menu = scan.nextInt();
switch(menu)
{
case 1:
remot.cekTV();
break;
case 2:
System.out.println("Pilih channel yang ingin ditonton");
System.out.println("1 - SCTV");
System.out.println("2 - INDOSIAR");
System.out.println("3 - RCTI");
System.out.println("4 - GLOBAL TV");
System.out.println("5 - TRANS TV");
System.out.println("6 - ANTV");
System.out.println("7 - NET TV");
int angka = scan.nextInt();
remot.gantichannel(angka);
break;
case 3:
System.out.println("Volume : " +remot.cekvolume()+ "\n");
break;
case 4:
int nilai = remot.cekvolume();
if(nilai < 100)
System.out.println("Volume : " +remot.tambahvolume()+ "\n");
break;
case 5:
int nilai_ = remot.cekvolume();
if(nilai_ > 0)
System.out.println("Volume : " +remot.kurangivolume()+ "\n");
break;
case 6:
tipe = 0;
System.out.println("##############");
System.out.println("#TV Dimatikan#");
System.out.println("##############");
break;
}
}
}
}
Tidak ada komentar:
Posting Komentar