Calculation of surface area and volume of rectangular and four pyramid

Source: Internet
Author: User

Calculation of surface area and volume of rectangular and four pyramid
Time limit:1000 Ms Memory limit:65536 KiB
Submit statistic
Problem Description
The surface area and volume of the three-dimensional figure are calculated.

From the diagram, we can extract the common attribute to the parent class rect: Length: L Width: h height: Z

In the parent class Rect, define Method area () for method length () and bottom area for the perimeter of the bottom surface.

Defines the subclass cube class cubic of the parent class rect, calculates the surface area and volume of the cube. The method in which the surface area () overrides the parent class.

Defines the subclass four pyramid class Pyramid of the parent class rect, calculates the surface area and volume of the pyramid. The method in which the surface area () overrides the parent class.

Enter the length (l), Width (h), and High (z) data of the cubic graph, respectively outputting the surface area and volume of the cuboid, the surface area and the volume of the pyramid.

Input
Enter multiple rows of numeric data (double);

Three values per line, representing L H Z, respectively

If there is a non positive number in the input data, it does not represent any graphics, surface area and volume are 0.

Output
The number of rows corresponds to the input, the numerical value is rectangular surface area cuboid Volume four Pyramid area Pyramid volume (there is a space in the middle as the interval, the value of two decimal places)

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
Four pyramid formula: v=1/3sh,s--Bottom Area h--high

Source
Zhouxq

Import java.util.*;
    Class rect{Double L, H, Z;
    Rect () {} Rect (double x, double y, double q) {L = x;h = Y;z = q;
    Double Zhouchang () {return 2* (l+h);
    Double area () {return l*h;
    } class Cubic extends rect{Cubic (double x, double y, double q) {super (x, y, q);
    Double area () {return 2* (h*l+l*z+h*z);
    Double V_cubic () {return h*l*z;
    } class Pyramid extends rect{pyramid (double x, double y, double q) {super (x, y, q);
    Double area () {return h*l + l*math.sqrt (z*z + H*H/4) + h*math.sqrt (Z*Z+L*L/4);
    Double V_pyramid () {return L*H*Z/3;
        } public class Main {public static void main (String []args) {Scanner cin = new Scanner (system.in);
            while (Cin.hasnext ()) {double L, h, Z;
            L = cin.nextdouble ();
            h = cin.nextdouble ();
            z = cin.nextdouble (); if (L&Lt;=0| | h<=0| |
                z<=0) {System.out.printf ("0.00 0.00 0.00 0.00\n");
            Continue
            } Cubic C = new Cubic (l, H, Z);
            Pyramid p = new Pyramid (l, H, Z);
        System.out.printf ("%.2f%.2f%.2f%.2f\n", C.area (), C.v_cubic (), P.area (), P.v_pyramid ());
    } cin.close (); }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.