ݺߣ

ݺߣShare a Scribd company logo
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("-------------------------------------------------------------------------");
}
}
Hasil Output
Program Fungsi Soal Latihan 2
package soallatihan2modul5;
import java.util.Scanner;
public class Soallatihan2modul5 {
static int []data=null;
static int n;
public static void main(String[] args) {
Scanner hagi = new Scanner(System.in);
int pilih;
do {
System.out.println("t MENU UTAMA");
System.out.println("----------------------------------------------");
System.out.println(" 1. input data");
System.out.println(" 2. tampilkan data");
System.out.println(" 3. statistik");
System.out.println(" 4. keluar");
System.out.println();
System.out.print(" Masukan pilihan : ");
pilih = hagi.nextInt();
switch (pilih){
case 1 : inputData();break;
case 2 : tampilkanData();break;
case 3 : statistik();break;}
} while (pilih!=4);}
private static void inputData(){
Scanner hagi = new Scanner(System.in);
System.out.println("================================================");
System.out.println("tt MENU INPUT DATA");
System.out.println("================================================");
System.out.print("Masukan jumlah data nilai siswa = ");
n = hagi.nextInt();
data = new int[n];
for (int i=0;i<n;i++){
System.out.print("Masukan data nilai siswa ke- "+(i+1)+" dari 1-100: ");
data[i]=hagi.nextInt();}
System.out.println("================================================");
System.out.println();}
private static void tampilkanData(){
if(data==null){
System.out.println("-Lakukan inputan dahulu-");
System.out.println();return;}
System.out.println("================================================");
System.out.println("tt MENU TAMPILAN DATA");
System.out.println("================================================");
System.out.println("Data yang anda input : ");
for(int i=0;i<n;i++){
System.out.println("Nilai siswa ke- "+(i+1)+" = "+data[i]+" ");}
System.out.println("================================================");
System.out.println();}
private static void statistik(){
if(data==null){
System.out.println("-Lakukan inputandahulu-");
System.out.println();return;}
double total=0;
for(int i=0;i<n;i++)
total+=data[i];
double rata=total/n;
int min=data[0],maks=data[0];
for(int i=0;i<n;i++){
if(data[i]<=min)
min=data[i];
if(data[i]>=maks)
maks=data[i];}
System.out.println("================================================");
System.out.println("tt MENU STATISTIK");
System.out.println("================================================");
System.out.printf("Nilai rata-rata : %.0fn",rata);
System.out.println("Nilai minimum : "+min);
System.out.println("Nilai maksimum : "+maks);
System.out.println("================================================");
System.out.println();}}
Hasil Ouput
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");
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();
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
Tugas praktek modul isbd
Tugas praktek modul isbd
Tugas praktek modul isbd

More Related Content

Tugas praktek modul isbd

  • 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("-------------------------------------------------------------------------");
  • 3. Program Fungsi Soal Latihan 2 package soallatihan2modul5; import java.util.Scanner; public class Soallatihan2modul5 { static int []data=null; static int n; public static void main(String[] args) { Scanner hagi = new Scanner(System.in); int pilih; do { System.out.println("t MENU UTAMA"); System.out.println("----------------------------------------------"); System.out.println(" 1. input data"); System.out.println(" 2. tampilkan data"); System.out.println(" 3. statistik"); System.out.println(" 4. keluar"); System.out.println(); System.out.print(" Masukan pilihan : "); pilih = hagi.nextInt(); switch (pilih){ case 1 : inputData();break; case 2 : tampilkanData();break; case 3 : statistik();break;} } while (pilih!=4);} private static void inputData(){ Scanner hagi = new Scanner(System.in); System.out.println("================================================"); System.out.println("tt MENU INPUT DATA"); System.out.println("================================================"); System.out.print("Masukan jumlah data nilai siswa = "); n = hagi.nextInt(); data = new int[n]; for (int i=0;i<n;i++){ System.out.print("Masukan data nilai siswa ke- "+(i+1)+" dari 1-100: "); data[i]=hagi.nextInt();} System.out.println("================================================"); System.out.println();} private static void tampilkanData(){ if(data==null){ System.out.println("-Lakukan inputan dahulu-"); System.out.println();return;} System.out.println("================================================"); System.out.println("tt MENU TAMPILAN DATA"); System.out.println("================================================"); System.out.println("Data yang anda input : "); for(int i=0;i<n;i++){ System.out.println("Nilai siswa ke- "+(i+1)+" = "+data[i]+" ");} System.out.println("================================================"); System.out.println();} private static void statistik(){ if(data==null){ System.out.println("-Lakukan inputandahulu-"); System.out.println();return;} double total=0; for(int i=0;i<n;i++) total+=data[i];
  • 4. double rata=total/n; int min=data[0],maks=data[0]; for(int i=0;i<n;i++){ if(data[i]<=min) min=data[i]; if(data[i]>=maks) maks=data[i];} System.out.println("================================================"); System.out.println("tt MENU STATISTIK"); System.out.println("================================================"); System.out.printf("Nilai rata-rata : %.0fn",rata); System.out.println("Nilai minimum : "+min); System.out.println("Nilai maksimum : "+maks); System.out.println("================================================"); System.out.println();}} Hasil Ouput
  • 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