NIM : 2012420044
Kelas : A
/accesor & mutator/
package balok;
import javax.swing.JOptionPane;
public class Balok {
private int tinggi;
private int panjang;
private int lebar;
public void setTinggi(int tinggi){
this.tinggi = tinggi;
}
public void setLebar(int lebar){
this.lebar = lebar;
}
public void setPanjang(int panjang){
this.panjang = panjang;
}
public int getPanjang(){
return tinggi;
}
public int getLebar(){
return lebar;
}
public int getTinggi(){
return tinggi;
}
public int getVolume(){
return tinggi*lebar*panjang;
}
public static void main(String[] args){
Balok z=new Balok();
z.lebar = Integer.parseInt(JOptionPane.showInputDialog("Masukkan Lebar : "));
z.tinggi= Integer.parseInt(JOptionPane.showInputDialog("Masukkan Tinggi : "));
z.panjang= Integer.parseInt(JOptionPane.showInputDialog("Masukkan Panjang : "));
JOptionPane.showMessageDialog(null, "Volume Balok adalah : "+z.getVolume());
}
}
hasil :
/overloading/
package gitar;
public class Gitar {
private String merk;
private String warna;
private String jenis;
public void setfitur(String aksi1){
this.merk=aksi1;
}
public void setfitur(String aksi1,String aksi2){
this.merk=aksi1;
this.warna=aksi2;
}
public void setfitur(String aksi1,String aksi2,String aksi3){
this.merk=aksi1;
this.warna=aksi2;
this.jenis=aksi3;
}
public void tampil(){
System.out.println(merk+warna+jenis);
}
public static void main(String[] args) {
Gitar g1,g2,g3;
g1 = new Gitar ();
g2 = new Gitar ();
g3 = new Gitar ();
g1.setfitur("yamaha "," ");
g2.setfitur("yamaha ","coklat ");
g3.setfitur("yamaha ","coklat ","nilon");
g1.tampil();
g2.tampil();
g3.tampil();
}
}
hasil :
Posted by 11.18 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar