public class Test { public static void main(String[] args) { int r = 50; int width = 40; int len = 60;

    double roundArea = 0;
    double rectArea = 0;

    TableInfo roundTable = new TableInfo("Round", 4, 100);
    TableInfo rectTable = new TableInfo("Rect", 4, 100);

    roundArea = roundTable.tableArea(r); // 计算圆桌面积
    rectArea = rectTable.tableArea(width, len); // 计算矩形桌面积

    System.out.println("Round Table Area =" + roundArea);
    System.out.println("Rect Table Area=" + rectArea);
}

}

class TableInfo { String shape; int legs; int hight;

public TableInfo(String shape, int legs, int hight) {
    this.shape = shape;
    this.legs = legs;
    this.hight = hight;
}

public void print() {
    System.out.println("Shape=" + shape);
}

// 计算圆桌面积的方法
public double tableArea(int r) {
    return 3.14 * r * r;
}

// 计算矩形桌面积的方法
public double tableArea(int a, int b) {
    return a * b;
}
请根据已知的程序代码补全类TableInfo的重构计算面积方法显示桌子面积。【输入形式】无【输出形式】Round Table Area =78500Rect Table Area=24000【样例输入】【样例输出】【样例说明】【评分标准】输出正确满分public class Test public static void mainString args

原文地址: https://www.cveoy.top/t/topic/eLmq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录