Return,Class,Getter,and Setter ...
Mencari luas dan keliling lingkaran :
package ele;
class circle{
private double jari;
private double pi;
public circle(){
jari = 0;
pi =3.14;
}
private double luasCircle(double r){
return pi*r*r;
}
private double keliling(double r){
return 2*pi*r;
}
public void setJari(double jari){
this.jari=jari;
}
public double getluas(){
return luasCircle(jari);
}
public double getkeliling(){
return keliling(jari);
}
public static void main(String args[]) {
circle c = new circle ();
c.setJari(7);
System.out.println("luas lingkaran = " + c.getluas());
System.out.println("keliling lingkaran = " + c.getkeliling());
}
}
OUTPUT :
luas lingkaran = 153.86
keliling lingkaran = 43.96
BUILD SUCCESSFUL (total time: 2 seconds)
package ele;
class circle{
private double jari;
private double pi;
public circle(){
jari = 0;
pi =3.14;
}
private double luasCircle(double r){
return pi*r*r;
}
private double keliling(double r){
return 2*pi*r;
}
public void setJari(double jari){
this.jari=jari;
}
public double getluas(){
return luasCircle(jari);
}
public double getkeliling(){
return keliling(jari);
}
public static void main(String args[]) {
circle c = new circle ();
c.setJari(7);
System.out.println("luas lingkaran = " + c.getluas());
System.out.println("keliling lingkaran = " + c.getkeliling());
}
}
OUTPUT :
luas lingkaran = 153.86
keliling lingkaran = 43.96
BUILD SUCCESSFUL (total time: 2 seconds)
Read Users' Comments (0)