1. Tugas Praktikum Struktur Data Modul 5
Praktikum 05
Program Fungsi Untuk Menentukan Suatu Bilangan (Prima/Bukan)
package soallatihanmodul05;
import java.util.Scanner;
public class Soallatihanmodul05 {
public static void main(String[] args) {
Scanner masukan=new Scanner(System.in);
int pilihan=9;
do{ System.out.println();
System.out.println("ttMENU UTAMA");
System.out.println("1. Menentukan bilangan prima atau bukan");
System.out.println("2. Menampilkan bilangan prima dari 1-100");
System.out.println("0. keluar");
System.out.print("Masukkan Pilihan Anda : ");
pilihan=masukan.nextInt();
switch(pilihan){
case 1:menentukan();break;
case 2:menampilkan();break;}
}while(pilihan!=0);}
private static void menentukan(){
Scanner masukan=new Scanner(System.in);
System.out.println();
System.out.println("-------------------------------------------------------------------------");
System.out.println("ttPROGRAM MENENTUKAN BILANGAN PRIMA ATAU BUKAN");
System.out.print("Masukkan Bilangan : ");
int bilangan = masukan.nextInt();
boolean prima=true;
for (int i=2;i<bilangan;i++){
if((bilangan%i)==0){
prima=false; break;}
}if (prima){
System.out.println(""+bilangan+" adalah bilangan PRIMA");}
else
System.out.println(""+bilangan+" adalah BUKAN bilangan PRIMA");
System.out.println("-------------------------------------------------------------------------");}
private static void menampilkan() {
System.out.println();
System.out.println("-------------------------------------------------------------------------");
System.out.println("ttPROGRAM MENAMPILKAN BILANGAN PRIMA DARI 1-100");
System.out.println("Berikut deret bilangan prima :");
int i, pembagi;
for (i=1;i<=100;i++) {
int x=0;
for (pembagi=2;pembagi<=i;pembagi++) {
if (i%pembagi==0) {
if (i!=pembagi) {
x = 1;}
if (x!=1&&i==pembagi) {
System.out.print(" "+i+"");}}}}
System.out.println();
System.out.println("-------------------------------------------------------------------------");
5. Tugas Praktikum 1
package Tugaspraktikummodul5;
import java.util.Scanner;
public class Tugaspraktikummodul5 {
static int kode;
static String nama,alamat, ktp, hp;
public static void main(String[] args) {
Scanner masukan=new Scanner(System.in);
int pilih;
do {System.out.println("---------------------------------------------------------");
System.out.println("tt MENU UTAMA");
System.out.println("---------------------------------------------------------");
System.out.println(" 1. Data Kamar");
System.out.println(" 2. Data Penyewa");
System.out.println(" 3. Data Transaksi");
System.out.println(" 4. keluar");
System.out.print(" Masukan pilihan : ");
pilih = masukan.nextInt();
switch (pilih){
case 1 : datakamar();break;
case 2 : datapenyewa();break;
case 3 : datatransaksi();break;}
} while (pilih!=4);}
private static void datakamar(){
System.out.println("tt DATA KAMAR");
6. System.out.println("=========================================================");
System.out.println("NO | TYPE |ISI|KETERSEDIAN| HARGA ");
System.out.println("1. | SINGLE | T | Y | RP. 150.000,- per malam");
System.out.println("2. | DOUBLE | T | Y | RP. 250.000,- per malam");
System.out.println("3. | SUITE | T | Y | RP. 350.000,- per malam");
System.out.println("=========================================================");
System.out.println("Total Semua Kamar : 50");
System.out.println("Total Kamar Kosong : 50");
System.out.println("Total Kamar Isi : 0");
System.out.println("DATA KAMAR KOSONG : - Single : 30");
System.out.println(" - Double : 10");
System.out.println(" - Suite : 10");
System.out.println("=========================================================");
}
private static void datapenyewa(){
Scanner masukan=new Scanner(System.in);
System.out.println("tt DATA PENYEWA");
System.out.println("=========================================================");
System.out.println("Masukkan Nama Anda : ");
nama=masukan.next();
System.out.println("Masukkan Alamat Anda : ");
alamat=masukan.next();
System.out.print("Masukkan NO KTP/SIM Anda : ");
ktp=masukan.next();
System.out.print("Masukkan NO Telepon Anda : ");
hp=masukan.next();
System.out.println(" PILIH KAMAR : ");
System.out.println(" 1. Single : Rp. 150.000,- per malam");
System.out.println(" 2. Double : Rp. 250.000,- per malam");
System.out.println(" 3. Suite : Rp. 350.000,- per malam");
System.out.print("Pilih kode kamar [1/2/3] : ");
kode=masukan.nextInt();
System.out.println("=========================================================");
}
private static void datatransaksi(){
Scanner masukan=new Scanner(System.in);
int single = 150000, db=250000, st=350000;
int total = 0, kembali, sewa;
System.out.println("tt DATA TRANSAKSI");
System.out.println("=========================================================");
System.out.println("t DATA YANG DI INPUTKAN");
System.out.println("Nama : "+nama);
System.out.println("Alamat : "+alamat);
System.out.println("NO KTP/SIM : "+ktp);
System.out.println("NO Telepon : "+hp);
if (kode==1)
{ System.out.println("Kamar yang di pesan : Single");
System.out.println("Harga Sewa : Rp. "+single+" per malam");
System.out.print ("Lama Sewa : ");
sewa=masukan.nextInt();
total=sewa*single;}
else if (kode==2)
{ System.out.println("Kamar yang di pesan : Double");
System.out.println("Harga Sewa : Rp. "+db+" per malam");
System.out.print ("Lama Sewa : ");
sewa=masukan.nextInt();
7. total=sewa*db;}
else if (kode==3)
{ System.out.println("Kamar yang di pesan : Suite");
System.out.println("Harga Sewa : Rp. "+st+" per malam");
System.out.print ("Lama Sewa : ");
sewa=masukan.nextInt();
total=sewa*st;}
else
{ System.out.println("Kode Yang Di Masukkan Salah");}
System.out.println("Total Bayar : Rp. "+total);
System.out.print ("Bayar : Rp. ");
int bayar=masukan.nextInt();
kembali=bayar-total;
System.out.println("Kembalian : Rp. "+kembali);
System.out.println("=========================================================");
}
}
Hasil Output