Program Pembelian Queue
LATIHAN MANDIRI QUEUE
Nama : Rayhan Qalby Ramadhan
NPM : 21082010008
- Tampilan Program
- Tampilan Output
- Source Code
cObject
package LatihanQueue;
public class cObject {
String nama;
String [][] pembelian = new String [5][5];
int total;
int antrian;
cObject next,prev;
cObject(String a,String [][] b,int c,int d){
nama=a;pembelian=b;total=c;antrian=d;
System.out.println("^Pesanan anda sedang diproses^");
System.out.println("Total Pembelian Anda : "+total);
}
}
cQueue
package LatihanQueue;
public class cQueue {
cObject front,rear;
int jumlah;
cQueue(){
System.out.println("Antrian Dibuat");
}
void enqueue(String a,String [][]b,int c,int d){ //tambah object dari belakang
cObject baru= new cObject(a,b,c,d);
if(front==null){ //antrian kosong
front=rear=baru;
}else{
rear.next=baru;
baru.prev=rear;
rear=baru;
}
jumlah++;
}
int dequeue(){ //hapus depan
String nm="";
String[][]beli=new String[5][5];
int total=0;
int u=0;
if(jumlah==0){
System.out.println("Antrian sudah kosong!");
}
else{
u=front.antrian;
total=front.total;
nm=front.nama;
beli=front.pembelian;
System.out.println("No.Urut Pesanan = ["+(u+1)+"]");
System.out.println("Pesanan Atas Nama = "+nm);
System.out.println("\n============ PESANAN =============");
for (int i = 0; i < 5; i++) {
if(beli[i][0]!=null){
System.out.println(beli[i][0]+"\t"+beli[i][1]+"\tRp."+beli[i][2]);
}
}
if(front.next==null){ front=rear=null; } //antrian = 1
else{ front=front.next; front.prev=null; } //antrian > 1
jumlah--;
}
return total;
}
void tampil(){
System.out.println("========= DAFTAR ANTRIAN =========");
System.out.println("No.Urut\t\tNama Pembeli");
String[][]beli=new String[5][5];
for (cObject t = front;t!= null;t=t.next) {
beli=t.pembelian;
System.out.println("["+(t.antrian+1)+"]"+"\t\t"+t.nama);
for (int i = 0; i < 5; i++) {
if(beli[i][0]!=null){
System.out.println("\t"+beli[i][0]+"\t"+beli[i][1]+"\tRp."+beli[i][2]);
}
}
}
System.out.println("");
}
}
cAppQueueBarang
package LatihanQueue;
import java.util.Scanner;
public class AppQueueBarang {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
cQueue q =new cQueue();
//variabel
String[] barang={"Sepatu Patrobas","Sepatu Ventela","Sepatu Compass","Sepatu Geoffmax","Sepatu Elfamous"};
int [] hrgbrg={240000,215000,400000,250000,300000};
int pilih=0;
int antrian=0;
int total=0;
int paid;
do{
System.out.println("========= SELAMAT DATANG =========");
System.out.println("========= Sapphire Store =========");
System.out.println(" 1. Pemesanan Barang");
System.out.println(" 2. Panggil Barang");
System.out.println(" 3. Tampilkan Barang");
System.out.println(" 4. Selesai");
System.out.print("Pilih = ");
pilih=sc.nextInt();
System.out.println("*********************************\n");
switch(pilih){
case 1:
total=0;
String [][] tampung=new String [5][5];
System.out.println("============= PESAN =============");
System.out.println("Pilih = 0 (Selesai)");
for (int i = 0; i < barang.length; i++) {
System.out.println("["+(i+1)+"] "+barang[i]+"\t Rp."+hrgbrg[i]);
}
int input;
int t=0;
do{
System.out.print("Nomor Barang = "); input=sc.nextInt();
if(input>5){
System.out.println("input salah!");
}else if(input!=0){
int ganti=0;
System.out.print("Jumlah Barang = "); int jml=sc.nextInt();
ganti=hrgbrg[input-1]*jml;
tampung[t][0]=barang[input-1];
tampung[t][1]=Integer.toString(jml);
tampung[t][2]=Integer.toString(ganti);
total=total+ganti;
t++;
}else if(input==0){
System.out.println("\n=================================");
System.out.println(" PESANAN ANDA ");
System.out.println("=================================");
System.out.println("Nama Barang\t\tJumlah\tHarga");
for (int i = 0; i < t; i++) {
if(tampung[i]!=null){
System.out.println(tampung[i][0]+"\t\t"+tampung[i][1]+"\tRp."+tampung[i][2]);
}
}
System.out.println(" \t\tTotal = Rp."+total);
System.out.print("\nPesanan Atas Nama = ");String nama = sc.next();
System.out.println("NOMOR PESANAN ANDA = "+(antrian+1));
q.enqueue(nama, tampung, total, antrian);
System.out.println("#################################\n");
antrian++;
}
}while(input!=0);
break;
case 2:
System.out.println("======== PANGGILAN ANTRIAN =======");
int bayar=q.dequeue();
System.out.println("Total Pembelian = Rp."+bayar);
do{
paid=0;
System.out.print("Uang Diterima = Rp.");paid=sc.nextInt();
}while(paid<bayar);
System.out.println("Uang Kembalian = Rp."+(paid-bayar));
break;
case 3:
q.tampil();
break;
case 4:
System.out.println("\n== Terimakasih Sudah Berbelanja ==");
System.out.println("===== Selamat Datang Kembali =====\n");
break;
}
}while(pilih!=4);
}
}
- Hasil Output
run:
Antrian Dibuat
========= SELAMAT DATANG =========
========= Sapphire Store =========
1. Pemesanan Barang
2. Panggil Barang
3. Tampilkan Barang
4. Selesai
Pilih = 1
*********************************
============= PESAN =============
Pilih = 0 (Selesai)
[1] Sepatu Patrobas Rp.240000
[2] Sepatu Ventela Rp.215000
[3] Sepatu Compass Rp.400000
[4] Sepatu Geoffmax Rp.250000
[5] Sepatu Elfamous Rp.300000
Nomor Barang = 1
Jumlah Barang = 2
Nomor Barang = 3
Jumlah Barang = 1
Nomor Barang = 0
=================================
PESANAN ANDA
=================================
Nama Barang Jumlah Harga
Sepatu Patrobas 2 Rp.480000
Sepatu Compass 1 Rp.400000
Total = Rp.880000
Pesanan Atas Nama = Rayhan
NOMOR PESANAN ANDA = 1
^Pesanan anda sedang diproses^
Total Pembelian Anda : 880000
#################################
========= SELAMAT DATANG =========
========= Sapphire Store =========
1. Pemesanan Barang
2. Panggil Barang
3. Tampilkan Barang
4. Selesai
Pilih = 1
*********************************
============= PESAN =============
Pilih = 0 (Selesai)
[1] Sepatu Patrobas Rp.240000
[2] Sepatu Ventela Rp.215000
[3] Sepatu Compass Rp.400000
[4] Sepatu Geoffmax Rp.250000
[5] Sepatu Elfamous Rp.300000
Nomor Barang = 2
Jumlah Barang = 1
Nomor Barang = 4
Jumlah Barang = 3
Nomor Barang = 0
=================================
PESANAN ANDA
=================================
Nama Barang Jumlah Harga
Sepatu Ventela 1 Rp.215000
Sepatu Geoffmax 3 Rp.750000
Total = Rp.965000
Pesanan Atas Nama = Rere
NOMOR PESANAN ANDA = 2
^Pesanan anda sedang diproses^
Total Pembelian Anda : 965000
#################################
========= SELAMAT DATANG =========
========= Sapphire Store =========
1. Pemesanan Barang
2. Panggil Barang
3. Tampilkan Barang
4. Selesai
Pilih = 1
*********************************
============= PESAN =============
Pilih = 0 (Selesai)
[1] Sepatu Patrobas Rp.240000
[2] Sepatu Ventela Rp.215000
[3] Sepatu Compass Rp.400000
[4] Sepatu Geoffmax Rp.250000
[5] Sepatu Elfamous Rp.300000
Nomor Barang = 5
Jumlah Barang = 2
Nomor Barang = 1
Jumlah Barang = 1
Nomor Barang = 0
=================================
PESANAN ANDA
=================================
Nama Barang Jumlah Harga
Sepatu Elfamous 2 Rp.600000
Sepatu Patrobas 1 Rp.240000
Total = Rp.840000
Pesanan Atas Nama = Ganesya
NOMOR PESANAN ANDA = 3
^Pesanan anda sedang diproses^
Total Pembelian Anda : 840000
#################################
========= SELAMAT DATANG =========
========= Sapphire Store =========
1. Pemesanan Barang
2. Panggil Barang
3. Tampilkan Barang
4. Selesai
Pilih = 3
*********************************
========= DAFTAR ANTRIAN =========
No.Urut Nama Pembeli
[1] Rayhan
Sepatu Patrobas 2 Rp.480000
Sepatu Compass 1 Rp.400000
[2] Rere
Sepatu Ventela 1 Rp.215000
Sepatu Geoffmax 3 Rp.750000
[3] Ganesya
Sepatu Elfamous 2 Rp.600000
Sepatu Patrobas 1 Rp.240000
========= SELAMAT DATANG =========
========= Sapphire Store =========
1. Pemesanan Barang
2. Panggil Barang
3. Tampilkan Barang
4. Selesai
Pilih = 2
*********************************
======== PANGGILAN ANTRIAN =======
No.Urut Pesanan = [1]
Pesanan Atas Nama = Rayhan
============ PESANAN =============
Sepatu Patrobas 2 Rp.480000
Sepatu Compass 1 Rp.400000
Total Pembelian = Rp.880000
Uang Diterima = Rp.900000
Uang Kembalian = Rp.20000
========= SELAMAT DATANG =========
========= Sapphire Store =========
1. Pemesanan Barang
2. Panggil Barang
3. Tampilkan Barang
4. Selesai
Pilih = 2
*********************************
======== PANGGILAN ANTRIAN =======
No.Urut Pesanan = [2]
Pesanan Atas Nama = Rere
============ PESANAN =============
Sepatu Ventela 1 Rp.215000
Sepatu Geoffmax 3 Rp.750000
Total Pembelian = Rp.965000
Uang Diterima = Rp.965000
Uang Kembalian = Rp.0
========= SELAMAT DATANG =========
========= Sapphire Store =========
1. Pemesanan Barang
2. Panggil Barang
3. Tampilkan Barang
4. Selesai
Pilih = 2
*********************************
======== PANGGILAN ANTRIAN =======
No.Urut Pesanan = [3]
Pesanan Atas Nama = Ganesya
============ PESANAN =============
Sepatu Elfamous 2 Rp.600000
Sepatu Patrobas 1 Rp.240000
Total Pembelian = Rp.840000
Uang Diterima = Rp.840000
Uang Kembalian = Rp.0
========= SELAMAT DATANG =========
========= Sapphire Store =========
1. Pemesanan Barang
2. Panggil Barang
3. Tampilkan Barang
4. Selesai
Pilih = 4
*********************************
== Terimakasih Sudah Berbelanja ==
===== Selamat Datang Kembali =====
BUILD SUCCESSFUL (total time: 1 minute 30 seconds)
Comments
Post a Comment