class Lingkaran
{
private double jari_jari;
public Lingkaran()
{
setJariJari(1);
}
public void Lingkaran(double r)
{
if(r>0)
jari_jari=r;
else
jari_jari=1.0;
}
public void setJariJari(double r)
{
if(r>0)
jari_jari=r;
}
public double getJariJari()
{
return(jari_jari);
}
public double hitungLuas()
{
return(Math.PI* jari_jari*jari_jari);
}
public double hitungKeliling()
{
return(Math.PI*2.0*jari_jari);
}
}
public class CobaLingkaran_2
{
public static void main(String args[])
{
Lingkaran abc=new Lingkaran();
Lingkaran pqr=new Lingkaran();
Lingkaran xyz=new Lingkaran();
pqr.setJariJari(5);
xyz.setJariJari(3.2);
System.out.println("Data Default");
System.out.println("=====================");
System.out.println("Jari-jari abc: " +abc.getJariJari());
System.out.println("Jari-jari pqr: " +pqr.getJariJari());
System.out.println("Jari-jari xyz: " +xyz.getJariJari());
System.out.println();
abc.setJariJari(5);
pqr.setJariJari(3.2);
xyz.setJariJari(1.8);
System.out.println("Data Sekarang: ");
System.out.println("=====================");
System.out.println("Jari-jari abc: " +abc.getJariJari());
System.out.println("Jari-jari pqr: " +pqr.getJariJari());
System.out.println("Jari-jari xyz: " +xyz.getJariJari());
System.out.println();
}
}
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar