1.Kelas Data_Barang
package toko;
public class Data_Barang {
private float harga_beli;
private float harga_jual;
private int barang_terjual;
public float penghasilan;
public Data_Barang(){}
public Data_Barang(float hb,float hj, int bt){
harga_beli=hb;
harga_jual=hj;
barang_terjual=bt;
}
public float getHB (){
return harga_beli;
}
public float getHJ (){
return harga_jual;
}
public float getBT (){
return barang_terjual;
}
public float getPENGHASILAN (){
penghasilan = (harga_jual-harga_beli)*barang_terjual;
return penghasilan;
}
}
2.Kelas Main_Toko
package toko;
import javax.swing.JOptionPane;
public class Main_Toko {
public static void main(String args[]) {
float harga_beli, harga_jual;
int barang_terjual;
float jumlah=0;
Data_Barang[] db;
db = new Data_Barang[5];
for (int i=0;i<db.length;i++){
int a = i+1;
harga_beli=Float.parseFloat(JOptionPane.showInputDialog(null,"masukkan harga beli barang "+a+": "));
harga_jual=Float.parseFloat(JOptionPane.showInputDialog(null,"masukkan harga jual barang "+a+": "));
barang_terjual=Integer.parseInt(JOptionPane.showInputDialog(null,"berapa banyak barang "+a+" terjual : "));
db[i]=new Data_Barang (harga_beli,harga_jual,barang_terjual);
}
for (int i=0;i<db.length;i++){
jumlah = db[i].getPENGHASILAN() + jumlah;
}
JOptionPane.showMessageDialog(null,"jumlah penghasilan toko = "+jumlah);
}
}
Minggu, 10 Juli 2011
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar