Advertisement
replicaJunction

OOP 1: Box

Jan 11th, 2013
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. /*
  2.  * This is a simple example class for learning and teaching Object-Oriented Programming.
  3.  * It demonstrates encapsulation by using get and set methods for its properties.
  4.  * It also demonstrates the fact that to the driver program, there is no difference between
  5.  * a raw property like Length and a calculated property like Volume.
  6.  *
  7.  * For more Object-Oriented Programming fundamentals, see the Container class:
  8.  * http://pastebin.com/EWyFnaXX
  9.  *
  10.  * Created by replicaJunction on 1/11/2013.
  11.  */
  12.  
  13. public class Box
  14. {
  15.     private int myLength, myWidth, myHeight;
  16.    
  17.     public Box(int l, int w, int h)
  18.     {
  19.         myLength = l;
  20.         myWidth = w;
  21.         myHeight = h;
  22.     }
  23.    
  24.     public int getLength()
  25.     {
  26.         return myLength;
  27.     }
  28.    
  29.     public void setLength(int l)
  30.     {
  31.         myLength = l;
  32.     }
  33.    
  34.     public int getWidth()
  35.     {
  36.         return myWidth;
  37.     }
  38.    
  39.     public void setWidth(int w)
  40.     {
  41.         myWidth = w;
  42.     }
  43.    
  44.     public int getHeight()
  45.     {
  46.         return myHeight;
  47.     }
  48.    
  49.     public void setHeight(int h)
  50.     {
  51.         return myHeight;
  52.     }
  53.    
  54.     public int getVolume()
  55.     {
  56.         return myLength * myWidth * myHeight;
  57.     }
  58.    
  59.     public int getSurfaceArea()
  60.     {
  61.         return (2 * myLength * myWidth) + (2 * myWidth * myHeight) + (2 * myHeight * myLength);
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement