Latihan Array Satu Dimensi 22082010015 Arsa Cahaya Pradipta

SOURCE CODE    : 

package com;


import java.util.*;


public class app {

    /**

     * @param args

     */

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);

        String menu[] = new String[100];

        int pilih[] = new int[100];

        int harga[] = new int[100];

        int jumlah[] = new int[100];

        int total[] = new int[100];

        int idx = 0, grand_total = 0;

        boolean selesai = false;


        System.out.println("----------------------------------------------");

        System.out.println("            DAFTAR MENU WARUNG JAVA           ");

        System.out.println("----------------------------------------------");


        System.out.println("1. Bakso                            Rp. 15.000");

        System.out.println("2. Nasi Ayam Geprek                 Rp. 12.000");

        System.out.println("3. Nasi Pecel                       Rp. 10.000");

        System.out.println("4. Nasi Campur                      Rp. 13.000");

        System.out.println("5. Teh                              Rp.  3.000");

        System.out.println("6. Jeruk                            Rp.  4.000");

        System.out.println("----------------------------------------------");


        System.out.println("Pilih 0 apabila telah selesai melakukan pemesanan");


        while (selesai == false) {


            System.out.print("Pilih Menu (0-6) : ");

            pilih[idx] = s.nextInt();


            if (pilih[idx] <= 6) {

                if (pilih[idx] == 0) {

                    selesai = true;

                } else {

                    switch (pilih[idx]) {

                        case 1:

                            menu[idx] = "Bakso           ";

                            harga[idx] = 15000;

                            break;

                        case 2:

                            menu[idx] = "Nasi Ayam Geprek";

                            harga[idx] = 12000;

                            break;

                        case 3:

                            menu[idx] = "Nasi Pecel      ";

                            harga[idx] = 10000;

                            break;

                        case 4:

                            menu[idx] = "Nasi Campur     ";

                            harga[idx] = 13000;

                            break;

                        case 5:

                            menu[idx] = "Teh             ";

                            harga[idx] = 3000;

                            break;

                        case 6:

                            menu[idx] = "Jeruk           ";

                            harga[idx] = 4000;

                            break;

                        default:

                            menu[idx] = "";

                            harga[idx] = 0;

                            break;

                    }

                    System.out.print("Jumlah porsi : ");

                    jumlah[idx] = s.nextInt();


                    total[idx] = jumlah[idx] * harga[idx];


                    grand_total += total[idx];

                    idx++;

                }

            } else {

                System.out.println("Silahkan memasukkan menu sesuai!!");

            }

        }


        System.out.println("------------------------------------------------------------------");

        System.out.println("                   INVOICE PEMBELIAN WARUNG JAVA                  ");

        System.out.println("------------------------------------------------------------------");

        System.out.println("No   Menu               Harga           Jumlah          Total     ");

        System.out.println("------------------------------------------------------------------");


        for (int i = 0; i < idx; i++) {

            System.out.println(

                    (i + 1) + ".  " + menu[i] + "    Rp." + harga[i] + "         " + jumlah[i] + "              Rp."

                            + total[i]);

        }


        System.out.println("------------------------------------------------------------------");

        System.out.println("Grand Total                                             Rp." + grand_total);

        System.out.println("------------------------------------------------------------------");


    }


}


HASIL PROGRAM :





Comments