Success

Get it in reality, not in a dream

Be Stronger

Stronger than the past

Craete your future

Your way is your choice

Be Faster

Make our move,create our future.

Make your dreams come true

Your dream is a picture of your future

Friday, October 5, 2012

PBO II


Latihan Java


class Handphone
{
// deklarasi
private String merk, tipe, warna;
private double harga;
// setter
public void setMerk(String merk){
this.merk = merk;
}
public void setTipe(String tipe){
this.tipe = tipe;
}
public void setWarna(String color){
this.warna = color;
}
public void setHarga(double harga){
this.harga = harga;
}
// getter
public String getMerk(){
return merk;
}
public String getTipe(){
return tipe;
}
public String getWarna(){
return warna;
}
public double getHarga(){
return harga;
}

// method tambahan
public double HargaDiskon() {
double diskon = 0.1 * getHarga();
double total = getHarga() - diskon;
return total;
}
public void keterangan() {
System.out.print("Harga HP sesudah diskon (10%) = " + HargaDiskon());
}
}

import java.io.*;
class Utama {
public static void main (String [] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try{
// instance of class
Handphone hp = new Handphone();
// input
System.out.print("Masukkan merk handphone :  ");
String merk_hp = br.readLine();
System.out.print("Masukkan tipe handphone :  ");
String tipe_hp = br.readLine();
System.out.print("Masukkan warna handphone :  ");
String warna_hp = br.readLine();
System.out.print("Masukkan harga handphone :  ");
double harga_hp = Double.parseDouble(br.readLine());
hp.setMerk(merk_hp);
hp.setTipe(tipe_hp);
hp.setWarna(warna_hp);
hp.setHarga(harga_hp);
// output
System.out.println("=============================");
System.out.println("DAFTAR HARGA PONSEL DAN SPEK");
System.out.println("=============================");
System.out.println("Merk HP = "+hp.getMerk());
System.out.println("Tipe HP = "+hp.getTipe());
System.out.println("Warna HP "+hp.getWarna());
System.out.println("Harga Sebelum Diskon ="+hp.getHarga());
hp.keterangan();
}catch(IOException e){
System.out.println("error bro");
}

}
}