新手写的课后练习,感觉基本能满足题目的要求... 有什么需要改进的地方吗?
package Shape; //父类
public abstract class Shape {
public abstract void ZhouChang();
public abstract void Area();
}
//长方形类
package Shape;
public class Rectangle extends Shape {
int length;
int width;
public Rectangle(int a,int b)
{
length=a;
width=b;
//System.out.println("长方形周长为"+Sum);
}
public void ZhouChang()
{
int total=(length+width)*2;
System.out.println("该长方形的周长为: "+total);
}
public void Area()
{
int area=length*width;
System.out.println(" 面积为: "+area);
//System.out.println("长方形的面积为"+area);
}
}
//圆形类
package Shape;
public class Circle extends Shape {
public final double PI=3.1415;
int R;
public Circle(int r)
{
this.R=r;//System.out.println("长方形周长为"+Sum);
}
public void ZhouChang()
{
double total=2*PI*R;
System.out.println("该圆形的周长为: "+total);
}
public void Area()
{
double area=PI*R;
System.out.println(" 面积为: "+area);
//System.out.println("长方形的面积为"+area);
}
}
//测试类
package Shape;
public class Initial {
static void main(String[] args) {
// TODO Auto-generated method stub
Shape one=new Rectangle(2,3);
one.ZhouChang();
one.Area();
Shape two=new Circle(3);
two.ZhouChang();
two.Area();
}
}