Nama : Novia Citra Fadhlilla
NPM : 22082010216
Kelas : E
SOURCE CODE :
package latihanarray;
import java.util.Scanner;
public class LatihanMultiDimensi {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String trx[][]= new String[3][4];
int harga []=new int [4];
int kode=101;
int baris=0,kolom=0,indeks=0;
int pilih=0,pilih2 = 0;
do{
System.out.println("");
System.out.println("----- MAHKOTA DIAMOND -----");
System.out.println("1. Transaksi Baru");
System.out.println("2. Rekap Transaksi");
System.out.println("3. Selesai");
System.out.println("-----------------------------------");
System.out.print("Pilih = ");
pilih=sc.nextInt();
switch(pilih){
case 1:
if(baris<=2){
kolom=0;
trx[baris][kolom]=String.valueOf(kode);
kolom=1;
do{
if(kolom<=3){
System.out.println("");
System.out.println("------ Pilih Barang ------");
System.out.println("1. Emas [Rp 3.000.000] ");
System.out.println("2. Berlian [Rp 5.000.000] ");
System.out.println("3. Permata [Rp 7.000.000] ");
System.out.println("4. Kembali");
System.out.println("-------------------------- ");
System.out.print("Pilih = ");
pilih2=sc.nextInt();
switch(pilih2){
case 1:
trx[baris][kolom]="Emas";
break;
case 2:
trx[baris][kolom]="Berlian";
break;
case 3:
trx[baris][kolom]="Permata";
break;
case 4:
System.out.println("Ke Menu Utama");
break;
}
kolom++;
}
else{
System.out.println("Transaksi 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(trx[i][j]!=null){
System.out.print(trx[i][j]+"\t");
}
}
System.out.println("");
}
break;
case 3:
System.out.println("TERIMA KASIH");
System.out.println("SELAMAT DATANG KEMBALI");
break;
}
}while(pilih!=3);
}
}
HASIL RUN :
----- MAHKOTA DIAMOND -----
1. Transaksi Baru
2. Rekap Transaksi
3. Selesai
-----------------------------------
Pilih = 1
------ Pilih Barang ------
1. Emas [Rp 3.000.000]
2. Berlian [Rp 5.000.000]
3. Permata [Rp 7.000.000]
4. Kembali
--------------------------
Pilih = 3
------ Pilih Barang ------
1. Emas [Rp 3.000.000]
2. Berlian [Rp 5.000.000]
3. Permata [Rp 7.000.000]
4. Kembali
--------------------------
Pilih = 4
Ke Menu Utama
----- MAHKOTA DIAMOND -----
1. Transaksi Baru
2. Rekap Transaksi
3. Selesai
-----------------------------------
Pilih = 3
TERIMA KASIH
SELAMAT DATANG KEMBALI
BUILD SUCCESSFUL (total time: 8 seconds)