Tugas Rumah PBO-B: Membuat Remote TV
Nama: Paramastri Ardiningrum
NRP: 05111740000019
Kelas: PBO - B
Kali ini, saya mengerjakan tugas rumah membuat remote tv menggunakan java dengan IDE BlueJ.
Class
Terdiri dari class RemoteTV dan class Main
Source Code
Untuk source code RemoteTV:
Untuk source code Main:
Run
Setelah di run dengan menginputkan berbagai macam case, kondisi-kondisi tertentu yang telah saya tentukan sudah teraplikasikan, dan jadilah seperti ini:
NRP: 05111740000019
Kelas: PBO - B
Kali ini, saya mengerjakan tugas rumah membuat remote tv menggunakan java dengan IDE BlueJ.
Class
Terdiri dari class RemoteTV dan class Main
Source Code
Untuk source code RemoteTV:
/**
* Membuat remote tv untuk tugas 3 PBO-B
*
* @author (Paramastri A)
* @version (21/9/2018)
*/
public class RemoteTV
{
private int channel;
private int volume;
public RemoteTV(int ch, int vl)
{
channel = ch;
volume = vl;
}
public int dapatkanChannel()
{
return channel;
}
public int dapatkanVolume()
{
return volume;
}
public int keraskanVolume()
{
volume++;
if(volume<=0)
{
volume=0;
System.out.println("Anda berada pada mode mute.");
}
else if(volume>20)
{
System.out.println("Volume suara lebih dari 20 tidak disarankan. Mohon pelankan demi keselamatan.");
}
System.out.println("Volume suara TV anda sekarang: "+volume+" ");
return volume;
}
public int pelankanVolume()
{
volume--;
if(volume<=0)
{
volume=0;
System.out.println("Anda berada pada mode mute.");
}
System.out.println("Volume suara TV anda sekarang: "+volume+" ");
return volume;
}
public int ubahChannelAtas()
{
channel++;
if(channel>5)
{
channel-=5;
}
System.out.println("Channel TV anda sekarang: "+channel+" ");
if(channel==1)
{
System.out.println("Selamat menonton RCTI!");
}
else if(channel==2)
{
System.out.println("Selamat menonton TRANS TV!");
}
else if(channel==3)
{
System.out.println("Selamat menonton SCTV!");
}
else if(channel==4)
{
System.out.println("Selamat menonton TV ONE!");
}
else if(channel==5)
{
System.out.println("Selamat menonton NET TV!");
}
return channel;
}
public int ubahChannelBawah()
{
channel--;
if(channel==0)
{
channel=5;
}
System.out.println("Channel TV anda sekarang: "+channel+" ");
if(channel==1)
{
System.out.println("Selamat menonton RCTI!");
}
if(channel==2)
{
System.out.println("Selamat menonton TRANS TV!");
}
if(channel==3)
{
System.out.println("Selamat menonton SCTV!");
}
if(channel==4)
{
System.out.println("Selamat menonton TV ONE!");
}
if(channel==5)
{
System.out.println("Selamat menonton NET TV!");
}
return channel;
}
}
Untuk source code Main:
import java.util.Scanner;
/**
* Membuat main dari projek remote tv untuk tugas 3 PBO-B
*
* @author (Paramastri A)
* @version (21/9/2018)
*/
public class Main
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
int channel, volume, mute, menu;
boolean tag;
do{
System.out.println("||||| INI REMOTE TV |||||");
System.out.println("Masukkan channel yang anda inginkan (1-5): ");
channel = scan.nextInt();
System.out.println("\nMasukkan volume yang anda inginkan (0-20): ");
volume = scan.nextInt();
} while((channel<=0 || channel>5) || (volume<0 || volume > 20));
RemoteTV remote = new RemoteTV(channel, volume);
tag = true;
while(tag)
{
System.out.println("||||| MENU |||||");
System.out.println("1. Info Channel");
System.out.println("2. Info Volume");
System.out.println("3. Tambah Channel");
System.out.println("4. Kurangi Channel");
System.out.println("5. Keraskan Volume");
System.out.println("6. Pelankan Volume");
System.out.println("7. Matikan TV");
menu = scan.nextInt();
switch(menu)
{
case 1:
channel = remote.dapatkanChannel();
System.out.println("Anda berada pada channel : "+channel+"");
if(channel==1)
{
System.out.println("Selamat menonton RCTI!");
}
else if(channel==2)
{
System.out.println("Selamat menonton TRANS TV!");
}
else if(channel==3)
{
System.out.println("Selamat menonton SCTV!");
}
else if(channel==4)
{
System.out.println("Selamat menonton TV ONE!");
}
else if(channel==5)
{
System.out.println("Selamat menonton NET TV!");
}
break;
case 2:
volume = remote.dapatkanVolume();
if(volume==0)
{
System.out.println("Anda berada pada mode mute.");
}
else if(volume>20)
{
System.out.println("Volume suara lebih dari 20 tidak disarankan.");
}
else{
System.out.println("Volume suara TV anda sekarang: "+volume+" ");
}
break;
case 3:
channel = remote.ubahChannelAtas();
break;
case 4:
channel = remote.ubahChannelBawah();
break;
case 5:
volume = remote.keraskanVolume();
break;
case 6:
volume = remote.pelankanVolume();
break;
case 7:
tag = false;
break;
}
}
}
}
Run
Setelah di run dengan menginputkan berbagai macam case, kondisi-kondisi tertentu yang telah saya tentukan sudah teraplikasikan, dan jadilah seperti ini:
Komentar
Posting Komentar