网站性能,视频 怎么做网站,品质好可以说品质什么,高端零食品牌有哪些Problem Description计算如下立体图形的表面积和体积。从图中观察#xff0c;可抽取其共同属性到父类Rect中#xff1a;长度#xff1a;l 宽度#xff1a;h 高度#xff1a;z在父类Rect中#xff0c;定义求底面周长的方法length( )和底面积的方法area( )。定义父类Rect…Problem Description计算如下立体图形的表面积和体积。从图中观察可抽取其共同属性到父类Rect中长度l 宽度h 高度z在父类Rect中定义求底面周长的方法length( )和底面积的方法area( )。定义父类Rect的子类立方体类Cubic计算立方体的表面积和体积。其中表面积area( )重写父类的方法。定义父类Rect的子类四棱锥类Pyramid计算四棱锥的表面积和体积。其中表面积area( )重写父类的方法。输入立体图形的长(l)、宽(h)、高(z)数据分别输出长方体的表面积、体积、四棱锥的表面积和体积。Input输入多行数值型数据(double)每行三个数值分别表示l h z若输入数据中有负数则不表示任何图形表面积和体积均为0。Output行数与输入相对应数值为长方体表面积 长方体体积 四棱锥表面积 四棱锥体积(中间有一个空格作为间隔数值保留两位小数)Example Input1 2 30 2 3-1 2 33 4 5Example Output22.00 6.00 11.25 2.000.00 0.00 0.00 0.000.00 0.00 0.00 0.0094.00 60.00 49.04 20.00Hint四棱锥体公式V1/3ShS——底面积 h——高很基础的题就是求四棱锥的表面积的公式麻烦点import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc new Scanner(System.in);while(sc.hasNext()){double lsc.nextDouble();double hsc.nextDouble();double zsc.nextDouble();Rect rectnew Cubic(l, h, z);rect.area(l, h, z);rect.volume(l,h,z);rectnew Pyramid(l, h, z);rect.area(l, h, z);rect.volume(l, h, z);}sc.close();}}class Rect {double l, h, z;public Rect(double l, double h, double z) {if(l0||h0||z0){l0;h0;z0;}this.l l;this.h h;this.z z;}public void volume(double l, double h, double z) {}public void length(double l, double h) {System.out.printf(%.2f ,2 * (this.l this.h));}public void area(double l, double h, double z) {System.out.printf(%.2f ,this.l * this.h);}}class Cubic extends Rect {public Cubic(double l, double h, double z) {super(l, h, z);}public void area(double l, double h, double z) {System.out.printf(%.2f ,2 * (this.h * this.l this.h * this.z this.z * this.l));}public void volume(double l, double h, double z) {System.out.printf(%.2f ,this.l * this.h * this.z);}}class Pyramid extends Rect{public Pyramid(double l, double h, double z) {super(l, h, z);}public void area(double l, double h, double z) {System.out.printf(%.2f ,Math.sqrt(this.h*this.h/4this.z*this.z)*this.lMath.sqrt(this.l*this.l/4this.z*this.z)*this.hthis.l*this.h);}public void volume(double l, double h, double z) {System.out.printf(%.2f\n,this.l *this. h * this.z/3);}}