Program Toko Buah [Array - Switch Case] 3 - JAVA

import java.util.Scanner;

public class Toko_Buah_Array_3
{
    public static void main (String []args)
    {
    Scanner Input = new Scanner (System.in);
    Scanner input = new Scanner (System.in);
    Scanner in = new Scanner (System.in);
    Scanner Masuk = new Scanner (System.in);
              
    //deklarasi
    int Transaksi = 10;
    int TotalTransaksi = 0;
    int[] JumlahBeli = new int[Transaksi];
    int[] Bayar = new int[Transaksi];
    int[] HargaKg = new int[Transaksi];
    int[] TotalBayar = new int[Transaksi];
    String Perintah=" ";
    String[] Kode = new String[Transaksi];
    String[] NamaBuah = new String[Transaksi];
    double[] Diskon = new double[Transaksi];
                                                              
    System.out.println("-------------------------------------------------------------");
    System.out.println("|      Kode      |      Nama Buah      |      Harga/Kg      |");
    System.out.println("-------------------------------------------------------------");
    System.out.println("|       A        |       Anggur        |     Rp.47.000,-    |");
    System.out.println("-------------------------------------------------------------");      
    System.out.println("|       J        |       Jeruk         |     Rp.30.000,-    |");
    System.out.println("-------------------------------------------------------------");
    System.out.println("|       M        |       Melon         |     Rp.20.000,-    |");
    System.out.println("-------------------------------------------------------------");
              
    //input
    do
    {
    System.out.print("\nBanyaknya Transaksi Jual - Beli : ");
    Transaksi = input.nextInt();
              
    //proses
    for (int n = 0; n < Transaksi; n++)
    {
        System.out.print("\nMasukan Kode Buah Ke - "+(n+1)+" : ");  
        Kode[n] = Input.nextLine();
      
        switch(Kode[n])
        {
            case "A":
                HargaKg[n]=47000;
                NamaBuah[n]="Anggur";
                break;
          
            case"J":
                HargaKg[n]=30000;
                NamaBuah[n]="Jeruk"; 
                break;
              
            case"M":      
                HargaKg[n]=20000;
                NamaBuah[n]="Melon";
                break;
              
            default:
                System.out.println("Input Yang Anda Masukan Salah");
        }
                      
        System.out.print("\nJumlah Beli Buah (Kg.) Ke - "+(n+1)+" : ");
        JumlahBeli[n] = in.nextInt();
                  
        Bayar[n]=HargaKg[n]*JumlahBeli[n];
        if(Bayar[n]>=300000)
        {
            Diskon[n]=Bayar[n]*0.1;
        }
        else
        {
            Diskon[n]=0;
        }
      
        TotalBayar[n]=(int)(Bayar[n]-Diskon[n]);
        TotalTransaksi=TotalTransaksi+TotalBayar[n];
    }
              
    //output
    System.out.println("\n                             TOKO BUAH SEGAR");
    System.out.println("=====================================================================================================");
    System.out.println("Kode Buah\tNama Buah\tHarga/Kg\tJumlah Beli (Kg.)\tBayar\tDiskon\tTotal Bayar");
    System.out.println("=====================================================================================================");
    for (int i = 0; i < Transaksi; i++)
    {  
    System.out.println("    "+Kode[i]+"            "+NamaBuah[i]+"           "+HargaKg[i]+"               "+JumlahBeli[i]+"                 "+Bayar[i]+"   "+Diskon[i]+ "   "+TotalBayar[i]);
    }
    System.out.println("=====================================================================================================");
    System.out.println("TOTAL TRANSAKSI   : "+TotalTransaksi);
    System.out.print("\nIngin Beli Buah Lagi? (Y/N) : ");
    Perintah=Masuk.nextLine();  
    }
    while(Perintah.equalsIgnoreCase("Y"));
}
}

NEXT

No comments:

Post a Comment