下面时我写的程序,本身没有问题的,请改进一下

public class Demo{

public static void main(String[] args){

Rectangle re=new Rectangle();

re.seta(2.5);

re.setb(2.8);

re.comput();

Circle ci=new Circle();

ci.seta(2.5);

ci.setb(3.5);

ci.comput();

}

}

abstract class Shapc{

private double a;

private double b;

public double geta(){

return a;

}

public void seta(double a){

this.a=a;

}

public double getb(){

return b;

public void setb(double b){

this.b=b;

}

public abstract void comput();

}


class Rectangle extends Shapc{

public void comput(){

double rectArea=geta()*getb();

double rectPerimeter=(geta()+getb())*2;

System.out.println("矩形的周长:"+rectPerimeter+",矩形的面积:"+rectArea);

}

}

class Circle extends Shapc{

public void comput(){

double cirArea=geta()*getb()*getb();

double cirPerimeter=geta()*getb()*2;

System.out.println("圆形的周长:"+cirPerimeter+",圆形的面积:"+cirArea);

}

}


慕瓜7080925
浏览 1318回答 2
2回答

mtexiy_Sss

改进是指?代码长度?还是变量规范?
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java