|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object hw2.Box
public class Box
This is a container can be used to contain Balls. The key difference between a BallContainer and a Box is that a Box has a finite volume. Once a box is full, a client cannot put in more Balls.
Constructor Summary | |
---|---|
Box(double maxVolume)
Constructor that creates a new box. |
Method Summary | |
---|---|
boolean |
add(Ball b)
This method is used to add Ball objects to this box of finite volume. |
void |
clear()
Empties the box, i.e. |
boolean |
contains(Ball b)
This method returns true if this box contains the specified Ball. |
Iterator<Ball> |
getBallsFromSmallest()
This method returns an iterator that returns all the balls in this box in ascending size, i.e., return the smallest Ball first, followed by Balls of increasing size. |
double |
getVolume()
Each Ball has a volume. |
Iterator<Ball> |
iterator()
Implements the Iterable interface for this box. |
boolean |
remove(Ball b)
Removes a ball from the box. |
int |
size()
Returns the number of Balls in this box. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Box(double maxVolume)
maxVolume
- Total volume of balls that this box can contain.Method Detail |
---|
public Iterator<Ball> iterator()
iterator
in interface Iterable<Ball>
public boolean add(Ball b)
b
- Ball to be added.
public Iterator<Ball> getBallsFromSmallest()
public boolean remove(Ball b)
b
- Ball to be removed.
public double getVolume()
public int size()
public void clear()
public boolean contains(Ball b)
b
- Ball to be checked if its in box
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |