Here's one class:
public class Box{
private double height, width, depth;
private boolean full;
public Box( double h, double w, double d){
height = h;
width = w;
depth = d;
full = false;
}
public boolean hasContents(){
if(full){return true;}
else {return false;}
}
public void fillBox(){ full = true; }
public void emptyBox() { full = false; }
public double getHeight(){return height;}
public double getWidth(){ return width;}
public double getDepth(){ return depth;}
public void setAll(double h, double w, double d){
height = h;
width = w;
depth = d;
}
public void setHeight(double h){height = h;}
public void setWidth(double w){width = w;}
public void setDepth(double d){depth = d;}
public double getVolume(){return (height*width*depth);}
public double getSurface(){return ( 2*(height*width) + 2*(height*depth) + 2*(depth*height) );} // assumes box has no opening for stuff to go in/out
public String toString(){
if(full) {return ("A full box that is " + height + " by " + width + " by " + depth + ".");}
else {return ("An empty box that is " + height + " by " + width + " by " + depth + ".");}
}
}
And the other:
public class boxTest{
public static void main(String [ ] args){
Box one = new Box( 1.0, 2.0, 3.0);
Box two = new Box( 2.0, 3.0, 4.0);
Box three = new Box( 3.0, 4.0, 5.0);
//fill all boxes with candy, but then eat all of box two's candy
one.fillBox();
two.fillBox();
three.fillBox();
two.emptyBox();
//makes you cry when you realize how much you've eaten
System.out.println("You ate " + two.getVolume() + " gallons of candy!");
//You modify the boxes so they can hold more candy.
one.setAll(5.0, 5.0, 5.0);
two.setAll(5.0, 5.0, 5.0);
three.setAll(5.0, 5.0, 5.0);
//syntax error
sag84htj jvbkdsnsd(fhgdsgd)
//info about boxes
System.out.println(one.toString());
System.out.println(two.toString());
System.out.println(three.toString());
}