2. 显示抽象类桌子子类圆桌和方桌面积1
【问题描述】请根据已知的程序代码,补全抽象类TableInfo,显示圆桌和方桌的信息。
【输入形式】无
【输出形式】
Round Table Area2826.0
Rect Table Area2400.0
【样例输入】
【样例输出】
【样例说明】
【评分标准】输出正确,满分
public class Test{
public static void main(String[] args)
{
TableInfo t1=new RoundTable (3, 100, 30.0);
TableInfo t2=new RectangleTable(4, 100, 40.0, 60.0);
System.out.println("Round Table Area" + t1.tableArea());
System.out.println("Rect Table Area" + t2.tableArea());
}
}
abstract class
TableInfo{
int legs;
int hight;
public TableInfo( int legs,int hight){
this.legs = legs;
this.hight = hight;
}
public abstract double tableArea();
}
class RectangleTable extends TableInfo{
private double len;
private double width;
public RectangleTable( int legs, int hight, double len, double width){
super(legs,hight);
this.len = len;
this.width = width;
}
public double tableArea(){
return len * width;
}
}
class RoundTable extends TableInfo{
private double r;
public RoundTable( int legs, int hight, double r){
super(legs, hight);
this.r = r;
}
public double tableArea(){
return 3.14 * r * r;
}
}