Program Queue, 22082010014 Risma Paramesti
Class appQueueAntrian :
package Queue;
import java.util.Scanner;
public class appQueueAntrian {
public static void main(String[] args) {
cAntrian antrian = new cAntrian();
Scanner scanner = new Scanner(System.in);
int pilih = 0;
do {
System.out.println("----------------------------------");
System.out.println("-------------- Queue -------------");
System.out.println("----------------------------------");
System.out.println(" 1. Tambah Antrian ");
System.out.println(" 2. Tampilkan Antrian ");
System.out.println(" 3. Proses Antrian ");
System.out.println(" 4. Keluar ");
System.out.println("----------------------------------");
System.out.print("Pilih : ");
pilih = scanner.nextInt();
System.out.println("");
switch (pilih) {
case 1:
System.out.print("Nama pembeli: ");
String namaPembeli = scanner.next();
System.out.print("Barang : ");
String Barang = scanner.next();
System.out.print("Harga barang: ");
int hargaBarang = scanner.nextInt();
antrian.enqueue(namaPembeli, Barang, hargaBarang);
System.out.println("");
System.out.println("Pembelian " + Barang + " oleh "
+ namaPembeli + " dengan harga "
+ hargaBarang + " telah ditambahkan ke dalam antrian");
System.out.println("");
break;
case 2:
antrian.tampilAntrian();
break;
case 3:
cPesanan processedItem = antrian.dequeue();
if(processedItem == null){
System.out.println("Antrian kosong..");
}else{
System.out.println("");
System.out.println("Pembelian " + processedItem.getBarang() + " oleh "
+ processedItem.getnamaPembeli() + " dengan harga "
+ processedItem.gethargaBarang() + " telah diproses");
System.out.println("");
}
break;
case 4:
System.out.println("Terimakasih...");
break;
default:
System.out.println("Pilihan tidak ada..");
break;
}
}while(pilih != 4);
}
}
Komentar
Posting Komentar