为了账号安全,请及时绑定邮箱和手机立即绑定

新手写的课后练习,感觉基本能满足题目的要求... 有什么需要改进的地方吗?

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();

   

}


}


正在回答

1 回答

  1. 包名统一小写 shape

  2. 方法名一般头字母小写

  3. public final double PI=3.1415;  public可以去掉吧 ,我不确定

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

新手写的课后练习,感觉基本能满足题目的要求... 有什么需要改进的地方吗?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信