array multi dimensi
ARRAY MULTI DIMENSI
NAMA: SYURAINI NOOR CHAMSYAH
KELAS: PAR A
NPM: 22082010033
SOURCE CODE:
package CobaCoba1;
import java.util.Scanner;
public class CobaCoba1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String transaksi[][]=new String[5][4];
String menu = "";
int kode=100;
int baris=0,kolom=0;
int pilih=0,pilih2=0;
do{
System.out.println("SELAMAT DATANG DI WARUNG SEDERHANA");
System.out.println("1. MENU MAKANAN");
System.out.println("2. REKAP TRANSAKSI");
System.out.println("3. SELESAI");
System.out.print("Pilih = ");
pilih=sc.nextInt();
switch(pilih){
case 1:
kode++;
kolom=0;
transaksi [baris][kolom]=String.valueOf(kode);
do{
System.out.println("PILIH MENU MAKANAN:");
System.out.print("1.NASI GORENG ");
System.out.print("2.NASI GILA ");
System.out.print("3.MIE GORENG ");
System.out.print("4.CAP CAY ");
System.out.print("5.SAYUR SAYUR");
System.out.println("6.Selesai");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
switch(pilih2){
case 1:
menu="NASI GORENG";
if(kolom<=2){
kolom++;
transaksi [baris][kolom]=menu;
}
break;
case 2:
menu="NASI GILA";
if(kolom<=2){
kolom++;
transaksi [baris][kolom]=menu;
}
break;
case 3:
menu="MIE GORENG";
if(kolom<=2){
kolom++;
transaksi [baris][kolom]=menu;
}
break;
case 4:
menu="CAP CAY";
if(kolom<=2){
kolom++;
transaksi [baris][kolom]=menu;
}
break;
case 5:
menu="SAYUR SAYUR";
if(kolom<=2){
kolom++;
transaksi [baris][kolom]=menu;
}
break;
case 6:
System.out.println("Kembali..");
break;
}
if(kolom>=3){
System.out.println("KERANJANG PENUH!");
break;
}
}while(pilih2!=6);
baris++;
break;
case 2:
System.out.println("Rekap Transaksi");
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]+" ");
}
System.out.println("");
}
break;
case 3:
System.out.println("Terima Kasih...");
}
}while(pilih!=3);
}
}
Komentar
Posting Komentar