LA DECIMA
Jumat, 30 Mei 2014
method accecor dan mutator (PBO 1)
pertama - tama buat class mahasiswa dulu ==>
public class Mahasiswa {
//atribut
String nim;
String nama;
String alamat;
String hp;
String facebook;
//constructor
public Mahasiswa(){
nim ="";
nama ="";
alamat ="";
hp ="";
facebook ="";
}
public Mahasiswa(String nim, String nama, String alamat, String hp, String facebook){
this.nim = nim;
this.nama = nama;
this.alamat = alamat;
this.hp = hp;
this.facebook = facebook;
}
//method
public void cetakProfil(){
System.out.println("Biodata");
System.out.println("===================================");
System.out.println("NIM : "+getNim());
System.out.println("Nama : "+getNama());
System.out.println("Alamat : "+getAlamat());
System.out.println("No. HP : "+getHp());
System.out.println("Facebook : "+getFacebook());
System.out.println("===================================");
System.out.println("STMIK Widya Pratama@2014");
System.out.println("===================================");
}
//method accecor
public String getNim(){
return nim;
}
public String getNama(){
return nama;
}
public String getAlamat(){
return alamat;
}
public String getHp(){
return hp;
}
public String getFacebook(){
return facebook;
}
// method mutator
public void setNim(String nim){
this.nim = nim;
}
public void setNama(String nama){
this.nama = nama;
}
public void setAlamat(String alamat){
this.alamat = alamat;
}
public void setHp(String hp){
this.hp = hp;
}
public void setFacebook(String facebook){
this.facebook = facebook;
}
}
kemudian buat class biodata2 untuk mengcompile and merunning programnya ==>
public class Biodata2{
public static void main(String[] args){
Mahasiswa mhs = new Mahasiswa("12.230.0000","cahiel","Pekalongan","08901081994","http://facebook/ioio");
mhs.cetakProfil();
mhs.setNim("12.230.0021");
mhs.setNama("Gusty Cahiel");
mhs.setAlamat("Proyonanggan Utara, Batang");
mhs.setHp("08925071994");
mhs.setFacebook("http://facebook.com/gusty");
mhs.cetakProfil();
Mahasiswa mhs2 = new Mahasiswa();
mhs2.cetakProfil();
mhs2.setNim("12.230.0021");
mhs2.cetakProfil();
}
}
Label:
java
Langganan:
Posting Komentar (Atom)
CAHIEL STORY
Design Template By cahiel gustyartono
Tidak ada komentar
Posting Komentar