import java.util.Scanner;
class Rect{
double l,h,z;
public Rect(double l,double h,double z){
this.l=l;
this.h=h;
this.z=z;
}
//在父类Rect中,定义求底面周长的方法length( )和底面积的方法area( )。
public double length(){
return 2*(l+h);
}
public double area(){
return l*h;
}
}
//定义父类Rect的子类立方体类Cubic,计算立方体的表面积和体积。其中表面积area( )重写父类的方法。
class Cubic extends Rect{
public Cubic(double l,double h,double z){
super(l,h,z);
}
public double v(){
return super.area()*z;
}
public double area(){
return length()*z+2*super.area();
}
}
//定义父类Rect的子类四棱锥类Pyramid,计算四棱锥的表面积和体积。其中表面积area( )重写父类的方法。
class Pyramid extends Rect{
public Pyramid(double l,double h,double z){
super(l,h,z);
}
public double area(){
return (l*h+(Math.sqrt(z*z+(h/2)*(h/2))*l)+(Math.sqrt(z*z+(l/2)*(l/2))*h));
}
public double v(){
return super.area()*z/3;
}
}
public class Main{
public static void main(String[] args){
//在主程序中,输入立体图形的长(l)、宽(h)、高(z)数据,分别输出长方体的表面积、体积、四棱锥的表面积和体积
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
double l,h,z;
l=sc.nextdouble();
h=sc.nextdouble();
z=sc.nextdouble();
if(l<=0||h<=0||z<=0)
{
System.out.println("0.00 0.00 0.00 0.00");
}
else{
Cubic Cubic=new Cubic(l,h,z);
Pyramid Pyramid=new Pyramid(l,h,z);
System.out.printf("%.2f %.2f %.2f %.2f\n",Cubic.area(),Cubic.v(),Pyramid.area(),Pyramid.v());
}
}
}
}
//Main.java:47: error: cannot find symbol
// l=sc.nextdouble();
// ^
// symbol: method nextdouble()
// location: variable sc of type Scanner
//Main.java:48: error: cannot find symbol
// h=sc.nextdouble();
// ^
// symbol: method nextdouble()
// location: variable sc of type Scanner
//Main.java:49: error: cannot find symbol
// z=sc.nextdouble();
// ^
// symbol: method nextdouble()
// location: variable sc of type Scanner
3 errors
nextdouble();
->
nextDouble();
大写!!!!!