Demo entry 6364891

Menghitung Harga Barang

   

Submitted by anonymous on May 17, 2017 at 10:55
Language: Java. Code size: 2.5 kB.

import java.util.Scanner;
public class Menghitung_Harga_Barang {
    public static void main (String[] args) {

        Scanner input = new Scanner(System.in);
        
        String Barang1, Barang2;
        int Total1, Total2;
        int JumlahBarang1, JumlahBarang2, TotalHarga = 0;
        int Gula = 5000; int Terigu = 6000; int Kopi = 3000;
        
        System.out.println("Nama Barang             Harga Satuan");
        System.out.println("Gula                    Rp. 5000");
        System.out.println("Terigu                  Rp. 6000");
        System.out.println("Kopi                    Rp. 3000 \n");
       
        System.out.print("Barang1 :");
        Barang1 = input.nextLine();
     
        System.out.print("JumlahBarang1 :");
        JumlahBarang1 = input.nextInt();
        
        switch (Barang1){
            case "Gula":
                System.out.print("Total : Rp. " + (Total1 = Gula * JumlahBarang1));
                System.out.print("\n");
            break;
            case "Terigu":
                System.out.print("Total : Rp. " + (Total1 = Terigu * JumlahBarang1));
                System.out.print("\n");
            break;
            case "Kopi":
                System.out.print("Total : Rp. " + (Total1 = Kopi * JumlahBarang1));
                System.out.print("\n");
            break;
            default:
                System.out.print("Barang tidak tersedia.");
                return;
        }
        
        Scanner masukan = new Scanner(System.in);
        
        System.out.print("Barang2 :  ");
        Barang2 = masukan.nextLine();
        
        System.out.print("JumlahBarang2 : ");
        JumlahBarang2 = masukan.nextInt();
        
        switch (Barang2){
            case "Gula":
                System.out.print("Total : Rp. " + (Total2 = Gula * JumlahBarang2 ));
                System.out.print("\n");
            break;
            case "Terigu":
                System.out.print("Total : Rp. " + (Total2 = Gula * JumlahBarang2 ));
                System.out.print("\n");
            break;
            case "Kopi":
                System.out.print("Total : Rp. " + (Total2 = Gula * JumlahBarang2 ));
                System.out.print("\n");
            break;
            default:
                System.out.print("Barang tidak tersedia.");
                return;
        }
        
        System.out.println("Jadi, total Harganya : Rp. " + (TotalHarga = Total1 + Total2));
        
      }
    }

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).