Mata Kuliah : Bahasa Pemrograman
Dosen : Bpk. Nur CahyoWibowo, S.Kom, M.Kom
Kelas : A35
NPM : 1535010006
Nama : Ulfa Emi Rahmawati
berikut source code pembuatan program menggunakan Array :
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tokoulfaemi2015;
import java.util.Scanner;
/**
*
* @author User
*/
public class transaksi {
public static void main(String args[]){
Scanner fa = new Scanner(System.in);
System.out.print("Jumlah barang yang dibeli : ");
int pilih= fa.nextInt();
String nama[]=new String[pilih];
int harga[]=new int[pilih];
int jumlah[]=new int [pilih];
int total[]=new int[pilih];
int tot=0;
for (int a=0;a<pilih;a++){
System.out.print("Nama barang ke- "+(a+1)+" : ");
nama[a]=fa.next();
System.out.print("Jumlah "+nama[a]+" : ");
jumlah[a]=fa.nextInt();
System.out.print("Harga "+nama[a]+" : ");
harga[a]=fa.nextInt();
total[a]=jumlah[a]*harga[a];
System.out.print("Total harga : "+total[a]);
tot=tot+total[a];
System.out.println();
}
System.out.println("==========================================================================================");
for (int a=0;a<pilih;a++) {
System.out.println("Nama Barang "+(a+1)+" : " +nama[a]+"\t Jumlah : "+jumlah[a] +" \t Harga : Rp"+harga[a]+",-"+" \t Total Harga : Rp"+total[a]+",-");
}
System.out.println ("Total Belanja = Rp"+tot+",-");
}
}
output dari program tersebut adalah :

Tidak ada komentar:
Posting Komentar