Pemrograman ke 8 (Array Multi Dimensi)
Source Code:
package array;
import java.util.Scanner;
public class LatArray2 {
public static void main(String[] args) {
Scanner N = new Scanner(System.in);
String transaksi[] [] = new String [3] [4];
int kode=101;
int baris=0, kolom=0;
int pilih=0, pilih2=0;
do{
System.out.println("Elite Motors");
System.out.println("1. Transaksi Baru");
System.out.println("2. Rekap Transaksi");
System.out.println("3. Selesai");
System.out.print("Pilih = ");
pilih = N.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("Pilih Mobil yang ingin dibeli");
System.out.println("1. Pagani Huayra");
System.out.println("2. Porsche 918 Spyder");
System.out.println("3. Ferrari Laferrari");
System.out.println("4. Kembali");
System.out.print("Pilih = ");
pilih2 = N.nextInt();
switch(pilih2){
case 1:
transaksi[baris][kolom] = "Pagani Huayra";
break;
case 2:
transaksi[baris][kolom] = "Porsche 918 Spyder";
break;
case 3:
transaksi[baris][kolom] = "Ferrari Laferrari";
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");
}
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("Terima Kasih Telah Berbelanja DI Elite Motors");
break;
}
}while(pilih!=3);
}
}
Output:
Komentar
Posting Komentar