clanecollege

Object Example - Rectangular Prism (Example.java)

May 16th, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. public class Example
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         RectPrism rp1 = new RectPrism(5, 6, 3);
  6.         RectPrism rp2 = new RectPrism(2, 3, 7);
  7.  
  8.         int volumeRP1 = rp1.getHeight() * rp1.getLength() * rp1.getWidth();
  9.         int volumeRP2 = rp2.getHeight() * rp2.getLength() * rp2.getWidth();
  10.  
  11.         int sAreaRP1 = (2 * rp1.getLength() * rp1.getHeight())
  12.                 + (2 * rp1.getLength() * rp1.getHeight())
  13.                 + (2 * rp1.getWidth() * rp1.getHeight());
  14.  
  15.         int sAreaRP2 = (2 * rp2.getHeight() * rp2.getLength())
  16.                 + (2 * rp2.getWidth() * rp2.getLength())
  17.                 + (2 * rp2.getWidth() * rp2.getHeight());
  18.  
  19.         /*
  20.          * The surface area and volume calculations are just here as an example.
  21.          * They can easily be implemented as methods in RectPrism.java
  22.          */
  23.  
  24.         System.out.println("Volume of rp1 is " + volumeRP1);
  25.         System.out.println("Volume of rp2 is " + volumeRP2);
  26.  
  27.         System.out.println("\nSurface Area of rp1 is " + sAreaRP1);
  28.         System.out.println("Surface Area of rp2 is " + sAreaRP2);
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment