Selasa, 06 November 2012

Contoh Program Java Harga Barang


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

import java.io.*;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Locale; import java.util.Scanner;

/**
 *
 * @author Advan
 */
public class NewClass {
    public static void main (String [] args) throws IOException {
        int goods;
        String pil;
        Locale l = new Locale("id", "ID");
    Currency c = Currency.getInstance("IDR");
    NumberFormat nf = NumberFormat.getCurrencyInstance(l);
    nf.setCurrency(c);
        goods=0;
        String op;
        System.out.println("Menu Pilihan :" );
        System.out.println("1. Buku");
        System.out.println("2. Flashdisk");
        System.out.println("3. CD");
        System.out.println("4. HardDisk");
        System.out.print("Masukkan Jenis Barang (1-4) : ");
        int price=0;
        Scanner tg0 = new Scanner(System.in);  
        int tg = Integer.parseInt(tg0.nextLine());
        switch (tg){
            case (1):           
                System.out.print("Masukkan Jumlah Barang : ");
                Scanner bu1 = new Scanner(System.in);  
                goods = Integer.parseInt(bu1.nextLine());
                price=50000;
                break;
            case (2):
                System.out.print("Masukkan Jumlah Barang : ");
                Scanner fl1 = new Scanner(System.in);
                goods = Integer.parseInt(fl1.nextLine());
                price=100000;
                break;
            case (3):
                System.out.print("Masukkan Jumlah Barang : ");
                Scanner cs1 = new Scanner(System.in);
                goods = Integer.parseInt(cs1.nextLine());
                price=10000;
                break;
            case (4):
                System.out.print("Masukkan Jumlah HardDisk : ");
                Scanner dd1 = new Scanner(System.in);
                goods = Integer.parseInt(dd1.nextLine());
                price=500000;
                break;
            default:
                System.out.println("Barang yang anda maksud tidak ada");
                System.exit(1);}
        System.out.println("--------------Terima Kasih------------------");
        int pay = goods*price;
        int discount;
        if (goods>=100) {
            discount = pay*30/100; }
        else if ((goods>50)&(goods<101)) {
            discount = pay*20/100; }
        else {
            discount = 0;}
        int SoPay=pay-discount;
        System.out.println("Total Belanjaan anda : ");
        System.out.println("Total harga : " +nf.format(pay));
        System.out.println("Diskon      : " +nf.format(discount));
        System.out.println("Total Bayar : " +nf.format(SoPay));
    }
}

0 komentar:

Posting Komentar