Array Satu Dimensi

Array Satu Dimensi

 Penerapan Array 1 Dimensi pada program kasir sederhana

Yanuar Hakam Rosyadi Ahmad (21082010079)



Berikut adalah source code dari program kasir "Kams Korean Street Food"

 

public static void main(String[] args) {
        Scanner s = new Scanner (System.in);
        String makanan [];
        makanan = new String [5];
        int harga [] = new int [5];
        int porsi []= new int [5];
        int subtotal [] = new int [5];
        int total=0,   indeks=0,  pilih=0,  uang, kembali;
        System.out.println("\tKams\t"+"\n Korean Street Foods");
        do{
            System.out.println("\nDaftar Menu :  "
           + "\n1. Odeng\tRp. 15.000" 
            + "\n2. Tteokbokki\tRp. 10.000"
            + "\n3. Gimbab      \tRp. 12.000"
            + "\n4. Twigim      \tRp. 8.000"
            + "\n5. Dakkoci   \tRp. 10.000"
            + "\n6. Selesai");
            System.out.print ("Pilih        : ");
            pilih=s.nextInt();
            switch (pilih){
                case 1:
                    makanan[indeks]="Odeng";
                    harga[indeks]=15000;
                    System.out.print("Jumlah porsi : ");
                    porsi [indeks] = s.nextInt();
                    subtotal[indeks]=porsi[indeks]*harga[indeks];
                       System.out.println("-----------------------------------");
                    break;
                case 2:
                    makanan[indeks]="Tteokbokki";
                    harga[indeks]=10000;
                    System.out.print("Jumlah porsi : ");
                    porsi [indeks] = s.nextInt();
                     subtotal[indeks]=porsi[indeks]*harga[indeks];
                        System.out.println("-----------------------------------");
                    break;
                case 3:
                    makanan[indeks]="Gimbab";
                    harga[indeks]=12000;
                    System.out.print("Jumlah porsi : ");
                    porsi [indeks] = s.nextInt();
                     subtotal[indeks]=porsi[indeks]*harga[indeks];
                     System.out.println("-----------------------------------");
                    break;
                case 4:
                   makanan[indeks]="Twigim";
                    harga[indeks]=8000;
                    System.out.print("Jumlah porsi : ");
                    porsi [indeks] = s.nextInt();
                    subtotal[indeks]=porsi[indeks]*harga[indeks];
                       System.out.println("-----------------------------------");
                    break;
                case 5:
                    makanan[indeks]="Dakkoci";
                    harga[indeks]=10000;
                    System.out.print("Jumlah porsi : ");
                    porsi [indeks] = s.nextInt();
                    subtotal[indeks]=porsi[indeks]*harga[indeks];
                       System.out.println("-----------------------------------");
                    break;
            } indeks++;
        } while (pilih!=6);
        //menampilkann daftar yang dibeli
          System.out.println("==========================");
        System.out.println("\nDAFTAR STRUK");
        for (int i = 0; i < indeks-1; i++) {
        System.out.println((i+1) + ".  "+ makanan[i]);
            System.out.println("    Jumlah\t: " +porsi[i]);
            System.out.println("    Sub Total\t: "+subtotal[i]);
            total=total+subtotal[i];
        }   System.out.println("\n---------------------------------------");
          System.out.println("TOTAL     \t: "+total);
          System.out.print("TUNAI     \t: ");
          uang=s.nextInt();
          kembali=uang-total;
          System.out.println("Kembalian \t: "+kembali);
          System.out.println("kam-sa-ham-ni-da"+"\nTerimakasih :)");
          System.out.println("==========================");  
    }