# 计算长方体、四棱锥的表面积和体积

Problem Description

Input

Output

Sample Input
1 2 3
0 2 3
-1 2 3
3 4 5
Sample Output
22.00 6.00 11.25 2.00
0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00
94.00 60.00 49.04 20.00
Hint

package pp;
import java.util.*;
class Rect{//父类
double l, h, z;

public Rect(double l, double h, double z) {
super();
if(l > 0 && h > 0 && z > 0) {//>0才表示图形
this.l = l;
this.h = h;
this.z = z;
}
}
public Rect() {

}

public double area() {
return this.l*this.h;
}
public double length() {
return 2*(this.l+this.h);
}
}

class Cubic extends Rect{//长方体
public Cubic(double l, double h, double z) {
super(l, h, z);
}
public double area() {//表面积
return super.area()*2 + super.length()*super.z;
}
public double vol(){
return super.area()*z;
}
}

class Pri extends Rect{//四棱锥
public Pri(double l, double h, double z){
super(l, h, z);
}
public double area(){
return super.area() +super.h*Math.sqrt(super.z*super.z  + super.l*super.l/4) +super.l * Math.sqrt(super.z*super.z  + super.h*super.h/4);

}
public double vol(){
return super.area()*z/3;
}
}

public class Main {

public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
double l = sc.nextDouble();
double h = sc.nextDouble();
double z = sc.nextDouble();
Cubic c = new Cubic(l, h, z);
Pri p = new Pri(l, h, z);
System.out.printf("%.2f %.2f %.2f %.2f\n", c.area(), c.vol(), p.area(), p.vol());
}
sc.close();
}
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120