小白请教怎样简化?
package com.imooc;
public abstract class Shape {
public abstract double perim();
public abstract double area();
-----------------------------------------------
public class Rectangle extends Shape {
double a=5.2;
double b=2.3;
double c=0;
double d=0;
@Override
public double perim() {
c=(a+b)*2;
System.out.println("矩形的周长:"+c);
return c;
// TODO Auto-generated method stub
}
@Override
public double area() {
d=a*b;
System.out.println("矩形的面积:"+d);
return d;
// TODO Auto-generated method stub
-------------------------------------------------------------
public class Circle extends Shape {
double e=3.14;
double r=2.5;
double j=0;
double i=0;
@Override
public double perim() {
j=2*e*r;
System.out.println("圆形的周长:"+j);
// TODO Auto-generated method stub
return j;
}
@Override
public double area() {
i=e*r*r;
System.out.println("圆形的面积:"+i);
// TODO Auto-generated method stub
return i;
}
-----------------------------------------------------
public class man {
public static void main(String[] args) {
// TODO Auto-generated method stub
Shape pe1 = new Rectangle();
pe1.perim();
pe1.area();
Shape pe2 = new Circle();
pe2.perim();
pe2.area();
}
--------------------------
矩形的周长:15.0
矩形的面积:11.959999999999999
圆形的周长:15.700000000000001
圆形的面积:19.625