Latihan Array 2 - JAVA

import java.util.Scanner;

public class Latihan_Array_2
{
    public static void main (String[] args)
    {

        Scanner input = new Scanner(System.in);       
       
        System.out.println("Berapa banyak barang yang ingin dibeli?");
        int barang = input.nextInt();
        String nama[] = new String[barang];
        int harga[] = new int[barang];
        int jumlah[] = new int[barang];
        int total[] = new int[barang];
        int tot=0;
       
        for (int b = 0; b < barang; b++)
        {
            System.out.print("Nama Barang "+(b+1)+" = ");
            nama[b] = input.next();
            System.out.print("Harga "+nama[b]+" = ");
            harga[b] = input.nextInt();
            System.out.print("Jumlah "+nama[b]+" = ");
            jumlah[b] = input.nextInt();
            total[b] = harga[b]*jumlah[b];
            System.out.println("Total Bayar = "+total[b]);
            System.out.println(" ");
            tot=tot+total[b];
        }
        System.out.println("------------------------------");
        System.out.println("-----    TOKO ARHAM ABADI   -----");
        System.out.println("----- Pamulang Timur - Pamulang -----");
        System.out.println("------------------------------");
        System.out.println(" ");
       
        for (int c = 0; c < barang; c++)
        {
            System.out.println("Barang ke- "+(c+1));
            System.out.println("1. Nama Barang   = "+nama[c]);
            System.out.println("2. Harga Barang  = "+harga[c]);
            System.out.println("3. Jumlah Barang = "+jumlah[c]);
        }
       
        System.out.println("_____________________________+");
        System.out.println("Total Belanjaan  = "+tot);
        System.out.println(" ");
        System.out.println("------------------------------");
        System.out.println("--Selamat berbelanja kembali--");
        System.out.println("----Anda beli, kami untung----");
        System.out.println("------------------------------");
    }
}
NEXT

No comments:

Post a Comment