Membuat Sistem Remote TV
1. Source code Remote
/**
* Membuat Program Remot Tv.
*
* @author (Christine Amelia)
* @version (5-23/09/2018)
*/
public class RemotTV
{
public boolean status,status1;
public int channel,volume,sign;
public RemotTV()
{
status=false;
channel=1;
volume=0;
}
public void StatusTV(boolean status1) //function to ON/OFF TV
{
if(status1==true)
{
status= false;
}
else
{
status= true;
}
}
public void ChannelTV(int sign)
{
if(status==false) //Cannot change the channel when the TV status is OFF
{
System.out.println("Please turn ON the TV");
}
else
{
if(sign==1)
{
if(channel<10)
{
channel++;
}
else
{
channel=1;
}
}
else
{
if(channel>1)
{
channel--;
}
else
{
channel=10;
}
}
}
}
public void VolumeTV(int sign)
{
if(status==false) //Cannot change the volume when the TV status is OFF
{
System.out.println("Please turn ON the TV");
}
else
{
if(sign==1)
{
if(volume<10)
{
volume++;
}
else
{
System.out.println("Volume maximum");
}
}
else
{
if(volume>0)
{
volume--;
}
else
{
System.out.println("Volume minimum");
}
}
}
}
}
2. Source code Main
/**
* Membuat Program Remot TV.
*
* @author (Christine Amelia)
* @version (5-23/09/2018)
*/
import java.util.Scanner;
public class MyMain
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int menu,pilihan;
RemotTV Rmt;
Rmt=new RemotTV();
while(true)
{
System.out.println("=================================================");
System.out.println("====================Remote TV====================");
System.out.println("=================================================");
System.out.print("====Status:");
if(Rmt.status==false) //check the TV status
{
System.out.print("Off===");
}
else
{
System.out.print("On===");
}
System.out.print("Volume:"+Rmt.volume+"===");
System.out.print("Channel:");
switch(Rmt.channel) //Switch channel
{
case 1:
System.out.println("1.RCTI========");
break;
case 2:
System.out.println("2.GLOBAL TV===");
break;
case 3:
System.out.println("3.MNC TV======");
break;
case 4:
System.out.println("4.TRANS TV====");
break;
case 5:
System.out.println("5.SCTV========");
break;
case 6:
System.out.println("6.Trans 7=====");
break;
case 7:
System.out.println("7.ANTV========");
break;
case 8:
System.out.println("8. TV ONE=====");
break;
case 9:
System.out.println("9. NET TV=====");
break;
case 10:
System.out .println("10.KOMPAS TV==");
break;
}
System.out.println("================Selamat Manyaksikan=============="); System.out.println("Menu:");
System.out.println("1. ON/OFF");
System.out.println("2. Maximal Volume");
System.out.println("3. Minimal Volume");
System.out.println("4. Channel (+)");
System.out.println("5. Channel (-)");
System.out.println("6. Choose Channel");
System.out.println("7. Exit\n");
System.out.println("Masukkan pilihan > ");
menu = sc.nextInt();
switch(menu)
{
case 1:
Rmt.StatusTV(Rmt.status); break; //change TV status
case 2:
Rmt.VolumeTV(1); break; //add TV volume
case 3:
Rmt.VolumeTV(0); break; //less TV volume
case 4:
Rmt.ChannelTV(1); break; //change TV channel
case 5:
Rmt.ChannelTV(0); break;
case 6:
System.out.println("Masukkan nomor channel (1-10) > ");
pilihan = sc.nextInt();
if(Rmt.status==false) //check the TV status
{
System.out.println("Nyalakan TV dahulu");
}
else
{
if(pilihan<1 || pilihan>10)
{
System.out.println("Channel tidak tersedia");
}
else
{
Rmt.channel=pilihan; //change to random channel
}
}
break;
case 7:
break;
}
if(menu==7)
{
break;
}
}
}
}
Hasil:
Tidak ada komentar:
Posting Komentar