public abstract String nama();
public abstract float kell();
public abstract float luas();
}
import java.util.Scanner;
public class Circle extends Shape{
private int jarijari;
public int getJarijari() {
return jarijari;
}
public void setJarijari(int jarijari) {
this.jarijari = jarijari;
}
public void jarijari(){
System.out.print("Jari-jari "+nama()+": ");
Scanner in=new Scanner(System.in);
jarijari=in.nextInt();
}
@Override
public String nama(){
String nama;
nama="Lingkaran";
return nama;
}
@Override
public float kell(){
float kell;
kell=(float)(2*3.14*getJarijari());
return kell;
}
@Override
public float luas() {
float area;
area = (float) (3.14*getJarijari()*getJarijari());
return area;
}
}
import java.util.Scanner;
public class Square extends Shape{
private int sisi;
public void sisi(){
System.out.print("Sisi persegi: ");
Scanner in= new Scanner(System.in);
sisi = in.nextInt();
}
public int getSisi() {
return sisi;
}
public void setSisi(int sisi) {
this.sisi = sisi;
}
@Override
public String nama() {
String nama;
nama="Persegi";
return nama;
}
@Override
public float kell() {
float kell;
kell=4*getSisi();
return kell;
}
@Override
public float luas() {
float luas;
luas=getSisi()*getSisi();
return luas;
}
}
import java.util.Scanner;
public class Rectangle extends Shape {
private int p, l;
public void panjang(){
System.out.print("Panjang "+nama()+" : ");
Scanner in=new Scanner(System.in);
p=in.nextInt();
}
public void lebar(){
System.out.print("Lebar "+nama()+" : ");
Scanner in=new Scanner(System.in);
l=in.nextInt();
}
public int getP() {
return p;
}
public void setP(int p) {
this.p = p;
}
public int getL() {
return l;
}
public void setL(int l) {
this.l = l;
}
@Override
public String nama() {
String nama;
nama="Persegi panjang";
return nama;
}
@Override
public float kell() {
float kell;
kell=2*(getP()+getL());
return kell;
}
@Override
public float luas() {
float luas;
luas=getP()*getL();
return luas;
}
}
public class AbstractMain {
public static void main(String[] args) {
Circle a=new Circle();
a.jarijari();
System.out.println("Keliling "+a.nama()+" adalah "+a.kell()+"\nLuas "+a.nama()+" adalah "+a.luas());
System.out.println("");
Square b=new Square();
b.sisi();
System.out.println("Keliling "+b.nama()+" adalah "+b.kell()+"\nLuas "+b.nama()+" adalah "+b.luas());
System.out.println("");
Rectangle c=new Rectangle();
c.panjang();
c.lebar();
System.out.println("Keliling "+c.nama()+" adalah "+c.kell()+"\nLuas "+c.nama()+ " adalah "+c.luas());
}
}
Posted by 02.10 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar