Minggu, 28 April 2013

menghitung luas dan keliling elip program java


penulis menjelaskan bagai mana cara menghitung luas dan keliling elip program java
berikut sourcodenya


import java.util.Scanner;
class Elips{
double phi = 3.14;
double Panjang;
double Lebar;

public Elips(double p, double l){
this.Panjang = p;
this.Lebar = l;
}
}

class Elips1 extends Elips{
public Elips1(double p, double l){
super(p,l);
}
public double getLuas(){
return (0.5*phi*Panjang*Lebar);
}
public double getKeliling(){
return (0.5*phi*(Panjang+Lebar));
}
}
class cetak{
public static void main(String[] args){
Scanner sc = new Scanner (System.in);
System.out.print("Sumbu Panjang: ");
double p = sc.nextDouble();
System.out.print("Sumbu Lebar: ");
double l = sc.nextDouble();
Elips1 elp1 = new Elips1 (p,l);
System.out.println("Keliling elips: "+elp1.getKeliling());
System.out.println("Luas Elips: "+elp1.getLuas());
}
}


Tidak ada komentar:

Poskan Komentar