Last active
August 29, 2015 14:20
-
-
Save agusmakmun/4036d5bac8699145046e to your computer and use it in GitHub Desktop.
Menghitung Luas dan Keliling di Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Ini adalah class SegiEmpat.java | |
Lihat class Pemanggilnya (getSegiEmpat.java): https://gist.github.com/agusmakmun/3ab29fd94476a65e2e94 | |
@author Summon Agus (L200130113) | |
@blog bloggersmart.net | |
*/ | |
public class SegiEmpat { | |
private int panjang = 20; //ganti dengan double untuk melihat perubahannya. | |
private int lebar = 10; | |
public void setPanjang(int panjang) { | |
this.panjang = panjang; | |
} | |
public void setLebar(int lebar) { | |
this.lebar = lebar; | |
} | |
public double getPanjang() { | |
return panjang; | |
} | |
public double getLebar() { | |
return lebar; | |
} | |
public double getLuas() { | |
return panjang * lebar; | |
} | |
public double getKeliling() { //double akan terdapat .0 | |
return 2*panjang + 2*lebar; | |
} | |
public void showValue() { | |
System.out.println("\nPanjang segi empat = "+panjang); | |
System.out.println("Lebar segi empat = "+lebar); | |
System.out.println("Luas segi empat = "+getLuas()); | |
System.out.println("Keliling segi empat = "+getKeliling()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment