I have this class
public class Box
{
int width;
int height;
int depth;
public Box(int a, int b, int c)
{
width = a;
height = b;
depth = c;
}
public void getWidth()
{
System.out.println(width);
}
public void getHeight()
{
System.out.println(height);
}
public void getDepth()
{
System.out.println(depth);
}
}
and this collection of boxes...
public class Collecton
{
int count = 0;
Box[] BoxCollection;
public Collection
{
BoxCollection = new Box[50]
for (count = 0; count < 50; count++){
BoxCollection = new Box(0,0,0)
}
}
public recbox(int a, int b, int c)
{
BoxCollection[count] = new Box(a, b, c)
count++
}
public printBoxes()
{
System.out.println("Box Number = " + count);
System.out.print("Box Width: "
BoxCollection[count].getWidth();
etc...
}
}
Now, I call this in the main code so that after each box is created, the specs of the box is printed back out onto the screen. The calling procedure works
However, only the Box Number part seems to print... the width, height and depth all don't work.
Am I accessing the data stored in the array of objects incorrectly?
Please advise.
Wierd thing is, if I add in a println line in my recbox method, like
System.out.println("W = "
BoxCollection.getWidth()
where is the number in the array, it prints out my info correctly. Otherwise by my print emthod, I am given the default 0,0,0 used to initialize the array
Thanks
public class Box
{
int width;
int height;
int depth;
public Box(int a, int b, int c)
{
width = a;
height = b;
depth = c;
}
public void getWidth()
{
System.out.println(width);
}
public void getHeight()
{
System.out.println(height);
}
public void getDepth()
{
System.out.println(depth);
}
}
and this collection of boxes...
public class Collecton
{
int count = 0;
Box[] BoxCollection;
public Collection
{
BoxCollection = new Box[50]
for (count = 0; count < 50; count++){
BoxCollection = new Box(0,0,0)
}
}
public recbox(int a, int b, int c)
{
BoxCollection[count] = new Box(a, b, c)
count++
}
public printBoxes()
{
System.out.println("Box Number = " + count);
System.out.print("Box Width: "
BoxCollection[count].getWidth();
etc...
}
}
Now, I call this in the main code so that after each box is created, the specs of the box is printed back out onto the screen. The calling procedure works
However, only the Box Number part seems to print... the width, height and depth all don't work.
Am I accessing the data stored in the array of objects incorrectly?
Please advise.
Wierd thing is, if I add in a println line in my recbox method, like
System.out.println("W = "
BoxCollection.getWidth()
where is the number in the array, it prints out my info correctly. Otherwise by my print emthod, I am given the default 0,0,0 used to initialize the array
Thanks