Forum Latihan Array Multi Dimensi
Source Code :
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String transaksi[][] = new String[3][4];
int kode = 101;
int harga = 0, total;
int baris=0, kolom=0;
int pilih=0, pilih2=0;
do{
System.out.println("");
System.out.println(" Selamat Datang ");
System.out.println(" Toko Buku Jaya ");
System.out.println("====================================");
System.out.println(" 1. Transaksi Baru ");
System.out.println(" 2. Rekap Transaksi ");
System.out.println(" 3. Selesai ");
System.out.println("====================================");
System.out.println("");
System.out.print("Pilih : ");
pilih = input.nextInt();
switch(pilih){
case 1:
if(baris<=2){
kolom=0;
transaksi[baris][kolom] = String.valueOf(kode);
kolom=1;
do{
if(kolom<=3){
System.out.println("");
System.out.println(" Daftar Barang Kami");
System.out.println("====================================");
System.out.println(" 1. Pensil Rp. 3000,00 ");
System.out.println(" 2. Bolpoint Rp. 5000,00 ");
System.out.println(" 3. Buku Rp. 4000,00 ");
System.out.println(" 4. Kembali ");
System.out.println("====================================");
System.out.print("Pilih Barang : ");
pilih2 = input.nextInt();
switch(pilih2){
case 1:
transaksi[baris][kolom] = "Pensil";
break;
case 2:
transaksi[baris][kolom] = "Bolpoint";
break;
case 3:
transaksi[baris][kolom] = "Buku";
break;
case 4:
System.out.println("Ke Menu Utama");
break;
}
kolom++;
}else {
System.out.println("Keranjang Penuh!");
break;
}
}while(pilih2 != 4);
baris++;
kode++;
}else{
System.out.println("Transaksi Penuh");
}
break;
case 2:
System.out.println("");
System.out.println("Rekap Transaksi");
System.out.println("Kode\tNama Barang");
for(int i=0; i<baris; i++){
for(int j=0; j<4; j++){
if(transaksi[i][j] != null){
System.out.print(transaksi[i][j] + "\t");
}
}
System.out.println("");
}
break;
case 3:
System.out.println("Terimakasih Telah Berbelanja");
break;
}
}while(pilih != 3);
}
Komentar
Posting Komentar