ok

Monday, 16 November 2015

Contoh Program Java Pakai Perulangan While

Class yang buat disini namanya contohfor anda dapat menggantinya sesuai nama class atau program yang kalian buat..!!!!
Selamat Mencobaa

import java.io.*;

public class contohfor{
     public static void main(String[] args)throws IOException{
        BufferedReader input;
        input = new BufferedReader(new InputStreamReader(System.in));
        String kb,nb,jb,tanya="ya";
        byte beli,data=1;
        Double total,jbayar,discon;
        Integer hb;
    
         while (data>0 && "ya".equals(tanya)) {
         System.out.println("Data ke "+data);
         System.out.print("Masukkan Kode Barang  = ");
        kb = input.readLine();
        System.out.print("Masukkan Jenis Barang = ");
        jb = input.readLine();
           if ("A".equals(jb)) {
                   hb = 50000;
                   nb = "Baju Kemeja";
           }
           else if("B".equals(jb)){
                   hb = 70000;
                   nb = "Celana Panjang";
           }
           else if("C".equals(jb)){
                   hb = 80000;
                   nb = "Topi";
           }
           else{
                   hb = 100000;
                   nb = "Sepatu";       
           }
        System.out.print("Masukkan Jumlah Beli  = ");
        beli = Byte.parseByte(input.readLine());
        System.out.println();
        System.out.println("      DATA PEMBELIAN BARANG  ");
        System.out.println("-----------------------------");
        System.out.println("Kode Barang "+kb+" Nama Barang "+nb);
        System.out.println("Harga Barang = "+hb);
        System.out.println("Jumlah Beli  = "+beli);
        jbayar=Double.valueOf(hb)*beli;
        System.out.println("Jumlah Bayar = "+(jbayar));
        if(beli > 5)
            discon = jbayar * 0.1;      
        else
            discon = 0.0; 
        System.out.println("Diskon       = "+discon);
        total=hb*beli-discon;
        System.out.println("Total Harga  = "+(total));
        System.out.println();
        System.out.print("Anda Ingin Memasukkan Data Lagi ? (ya/tidak) = ");
        tanya = input.readLine();
        System.out.println();
        data++;
       } 
    }
}
Share:

Baca Juga Artikel

Like

Rusdyanha.com