Rabu, 28 November 2012

Tugas Applikasi Penjualan Fried Chicken Menggunakan Java



public class Tugas {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
       
        System.out.println("=========GEROBAK FRIED CHIKEN==============");
        System.out.println("===========================================");
        System.out.println("No==Jenis ====Harga====Banyak====Jumlah====");
        System.out.println("====Potong====Satuan===Beli======Harga=====");
        // Untuk memasukan berapa banyak jenis yang akan dibeli
        System.out.print("Masukan Banyak Jenis ");


        int banyak_jenis = input.nextInt();

        String[] jenis = new String[banyak_jenis];
        int[] jumlah_potong = new int[banyak_jenis];
        int[] harga = new int[banyak_jenis];
        int[] jumlah_bayar = new int[banyak_jenis];
        double total_bayar = 0;
        String[] kode = new String[banyak_jenis];
       
        for (int i = 0; i < jumlah_potong.length; i++) {
            System.out.print("Masukan Jenis ");          
            jenis[i] = input.next();
            System.out.println();
            System.out.print("Jumlah Potong  = ");
            jumlah_potong[i] = input.nextInt();
            System.out.println();
        }

        // Sort
        for (int i = jumlah_potong.length - 1; i >= 1; i--) {
        // Find the maximum in the jumlah_potong[0..i]
            int currentMax = jumlah_potong[0];
            int currentMaxIndex = 0;

            for (int j = 1; j <= i; j++) {
                if (currentMax < jumlah_potong[j]) {
                    currentMax = jumlah_potong[j];
                    currentMaxIndex = j;
                }
            }

        // Swap jumlah_potong[i] dengan jumlah_potong[currentMaxIndex];
        // Swap jenis[i] dengan jenis[currentMaxIndex] ;
            if (currentMaxIndex != i) {
                jumlah_potong[currentMaxIndex] = jumlah_potong[i];
                jumlah_potong[i] = currentMax;
                String temp = jenis[currentMaxIndex];
                jenis[currentMaxIndex] = jenis[i];
                jenis[i] = temp;
            }
        }
     
        System.out.println("=========GEROBAK FRIED CHIKEN====================");      
        System.out.println("No\tJenis \tHarga\tBanyak\tJumlah\t");
        System.out.println("  \tPotong\tSatuan\tBeli\tHarga\t");
        System.out.println("=================================================");
        int no = 1;
        for (int i = 0; i < jenis.length; i++) {
            if(jenis[i].equalsIgnoreCase("Paha")){
                harga[i] = 2500;
                kode[i] = "P";
            }else if(jenis[i].equalsIgnoreCase("Sayap")){
                harga[i] = 2000;
                kode[i] = "S";
            }else {
                harga[i] = 3000;
                kode[i] = "D";
            }
            System.out.println(no+".\t"+jenis[i] +"\t"+harga[i]+"\t"+ jumlah_potong[i]+"\t Rp. "+ (jumlah_bayar[i] =(harga[i]* jumlah_potong[i])));
            total_bayar += jumlah_bayar[i];
            no++;
        }
        System.out.println("=================================================");
        System.out.println("Jumlah Bayar Rp. "+total_bayar);
        System.out.println("Pajak 10 = Rp. "+ (total_bayar * (0.1)));
        System.out.println("Total Bayar = Rp. "+ (((0.1)*total_bayar)+total_bayar));
    }
}

Silahkan konversi ke C++ untuk tugas di kampus...

Tidak ada komentar:

Posting Komentar