Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This is another simple example class for Object-Oriented Programming.
- * It represents a container that can have another box inside it - but you can only put something in it
- * or see what's in it if the container is open (think of it as an opaque lid). You can also only
- * store things in the Container that are smaller than the Container is. Modifying this class so that
- * it checks not just the total volume, but also each individual side, is left as an exercise to the
- * user.
- *
- * This class extends the Box class here: http://pastebin.com/mCu64xbP
- *
- * Created by replicaJunction on 1/11/2013.
- */
- public class Container extends Box
- {
- private Box myContents;
- private boolean isOpen;
- public Container(int l, int w, int h)
- {
- super(l, w, h);
- isOpen = false;
- }
- public void open()
- {
- isOpen = true;
- }
- public void close()
- {
- isOpen = false;
- }
- public Box getContents()
- {
- if (isOpen)
- return myContents;
- else
- return null;
- }
- public boolean setContents(Box newContents)
- {
- if (isOpen == false)
- return false;
- int contentVolume = newContents.getVolume();
- if (contentVolume >= getVolume() )
- return false;
- myContents = newContents;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement