Kuliah minggu ke-4 PBO yang lalu, kelas saya mendapatkan tugas untuk membuat Remot TV menggunakan BlueJ.
Berikut adalah source code nya:
Main:
RemotTV
Berikut adalah hasilnya:
Berikut adalah source code nya:
Main:
/**
* Write a description of class Main here.
*
* @author (Ahmad Syauqi)
* @version (1.0)
*/
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
int menu, channel, volume;
menu=0;
channel=0;
volume=0;
System.out.println("SUMSANG");
RemotTV remot = new RemotTV();
while(menu!=9)
{
System.out.println("1. Get Channel");
System.out.println("2. Get Volume");
System.out.println("3. Set Channel");
System.out.println("4. Set Volume");
System.out.println("5. Next Channel");
System.out.println("6. Previous Channel");
System.out.println("7. Up Volume");
System.out.println("8. Down Volume");
System.out.println("9. Turn Off");
menu=scan.nextInt();
switch(menu)
{
case 1:
channel=remot.getChannel();
System.out.println("Anda berada di channel "+channel);
break;
case 2:
volume=remot.getVolume();
System.out.println("Volume: "+volume);
break;
case 3:
System.out.println("Masukkan channel yang anda tuju");
channel=scan.nextInt();
remot.setChannel(channel);
break;
case 4:
System.out.println("Masukkan volume yang anda inginkan");
volume=scan.nextInt();
remot.setVolume(volume);
break;
case 5:
remot.nextChannel();
break;
case 6:
remot.preChannel();
break;
case 7:
remot.upVolume();
break;
case 8:
remot.downVolume();
break;
case 9:
System.out.println("SUMSANG");
System.out.println("#######");
break;
}
}
}
}
RemotTV
/**
* Write a description of class RemotTV here.
*
* @author (Ahmad Syauqi)
* @version (1.0)
*/
public class RemotTV
{
private int channel;
private int volume;
public RemotTV()
{
channel = 0;
volume = 0;
}
public int getChannel()
{
return channel;
}
public int getVolume()
{
return volume;
}
public void nextChannel()
{
if (channel < 16) channel = channel + 1;
else channel = 0;
}
public void preChannel()
{
if (channel > 0) channel = channel -1;
else channel = 16;
}
public void setChannel(int cha)
{
if (cha>=0 && cha<=16) channel = cha;
}
public void upVolume()
{
if (volume < 100) volume = volume +1;
}
public void downVolume()
{
if (volume > 0) volume = volume - 1;
}
public void setVolume(int vol)
{
if (vol>=0 && vol<=100) volume = vol;
}
}
Berikut adalah hasilnya:
Komentar
Posting Komentar