Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This is a simple example class for learning and teaching Object-Oriented Programming.
- * It demonstrates encapsulation by using get and set methods for its properties.
- * It also demonstrates the fact that to the driver program, there is no difference between
- * a raw property like Length and a calculated property like Volume.
- *
- * For more Object-Oriented Programming fundamentals, see the Container class:
- * http://pastebin.com/EWyFnaXX
- *
- * Created by replicaJunction on 1/11/2013.
- */
- public class Box
- {
- private int myLength, myWidth, myHeight;
- public Box(int l, int w, int h)
- {
- myLength = l;
- myWidth = w;
- myHeight = h;
- }
- public int getLength()
- {
- return myLength;
- }
- public void setLength(int l)
- {
- myLength = l;
- }
- public int getWidth()
- {
- return myWidth;
- }
- public void setWidth(int w)
- {
- myWidth = w;
- }
- public int getHeight()
- {
- return myHeight;
- }
- public void setHeight(int h)
- {
- return myHeight;
- }
- public int getVolume()
- {
- return myLength * myWidth * myHeight;
- }
- public int getSurfaceArea()
- {
- return (2 * myLength * myWidth) + (2 * myWidth * myHeight) + (2 * myHeight * myLength);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement