Iseng – Contoh Program Java Sederhana – transfer bank

sekedar iseng sih, bantuin adek kost semester 2 yang lagi belajar object oriented programming. Java nih, udah lama gak megang sih, tapi untuk program sesederhana ini, saya masih lancar lah~~ heuheuheu…  cuma contoh transfer bank sederhana..

public class nasabah{

//deklarasi variabel
private String nama;
private int norek;
private int saldo;
private int jumlah;

public nasabah ( string nama, int norek, int saldo){
this.nama=nama;
this.norek=norek;
this saldo=saldo;
}

//buat method untuk ceksaldo

public void ceksaldo(){
System.out.println(“Nama Anda : “+nama);
System.out.println(“Nomor Rekening Anda : “+norek);
System.out.println(“Saldo Anda Saat Ini : “+saldo);
}

//method setorUang, return valuenya adalah saldo

public int setorUang(int jumlah){
this.jumlah=jumlah;
saldo=saldo-jumlah;
return saldo;
}

//method tarikUang, return valuenya adalah jumlah yg ditarik

public int terimaUang(int jumlah){
this.jumlah=jumlah;
saldo=saldo+jumlah;
return jumlah;
}

public static void main (String args[]){

//buat object dari class nasabah
nasabah nasabah1 = new nasabah (“nasabah 1”,123,500000);
nasabah nasabah2 = new nasabah (“nasabah 2”,123,300000);

nasabah1.ceksaldo();
nasabah2.ceksaldo();

//transfer
int jumlahtransfer=100000;

System.out.println(“====Saldo nasabah setelah transfer sejumlah “+jumlahtransfer+”====”);

nasabah1.tarikUang(nasabah2.terimaUang(jumlahtransfer));

nasabah1.ceksaldo();
nasabah2.ceksaldo();

}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s