编写求解几何图形(如三角形。矩形。圆)的周长、面积的几何应用,要求用到继承、多态、抽象类、接口、内部类等面向对象程序设计的特点。
import java.util.*;
import java.lang.*;
class Triangle extends Jihe{
public Triangle(double m,double n,double q)
{
super(m,n,q);
}
}
class Rectangle extends Jihe{
public Rectangle(double a,double b)
{
super(a,b);
}
}
class Round extends Jihe{
public Round(double r)
{
super(r);
}
}
class Jihe{
double c;
double s;
double p;
public Jihe(double r){
c=2*3.14*r;
s=3.14*r*r;
System.out.println(c+","+s);
}
public Jihe(double a,double b){
c=2*a+2*b;
s=a*b;
System.out.println(c+","+s);
}
public Jihe(double m,double n,double q){
c=m+n+q;
p=c/2;
s=Math.sqrt(p*(p-m)*(p-n)*(p-q));
System.out.println(c+","+s);
}
}
class Test{
public static void main(String [] args){
Scanner n=new Scanner(System.in);
double a,b,c,d,e,f;
a=n.nextDouble();
b=n.nextDouble();
c=n.nextDouble();
d=n.nextDouble();
e=n.nextDouble();
f=n.nextDouble();
Triangle t1=new Triangle(a,b,c);
Round t2= new Round(d);
Rectangle t3= new Rectangle(e,f);
}
}