Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Example
- {
- public static void main(String[] args)
- {
- RectPrism rp1 = new RectPrism(5, 6, 3);
- RectPrism rp2 = new RectPrism(2, 3, 7);
- int volumeRP1 = rp1.getHeight() * rp1.getLength() * rp1.getWidth();
- int volumeRP2 = rp2.getHeight() * rp2.getLength() * rp2.getWidth();
- int sAreaRP1 = (2 * rp1.getLength() * rp1.getHeight())
- + (2 * rp1.getLength() * rp1.getHeight())
- + (2 * rp1.getWidth() * rp1.getHeight());
- int sAreaRP2 = (2 * rp2.getHeight() * rp2.getLength())
- + (2 * rp2.getWidth() * rp2.getLength())
- + (2 * rp2.getWidth() * rp2.getHeight());
- /*
- * The surface area and volume calculations are just here as an example.
- * They can easily be implemented as methods in RectPrism.java
- */
- System.out.println("Volume of rp1 is " + volumeRP1);
- System.out.println("Volume of rp2 is " + volumeRP2);
- System.out.println("\nSurface Area of rp1 is " + sAreaRP1);
- System.out.println("Surface Area of rp2 is " + sAreaRP2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment