i have an Array of objects and want to add an ArrayList of a different ob
could someone please help me out with this one,
when the table is created i need create one new pile to each element of this array
create one new block for each pile
add a block to the pile
the block is an arraylist
the block and pile classes have already been set up
public class Table
{
private int NPILES;// the number of piles
private Pile[] piles; // the array of piles
/** Create a table and initialise the array piles.
* For every pile created create a block
*/
public Table(int npiles)
{
// Initialise NPILES
NPILES = npiles;
// Create the array of size NPILES
piles = new Pile[NPILES];
for (int i = 0; i < NPILES; i++) {
}
}
/** Print the table. */
public void print()
{
System.out.println("");
System.out.println("P = Piles : B = Blocks");
System.out.println("");
System.out.println("P : B");
// Print the sequence of piles
for (int i = 0; i < NPILES; i++) {
System.out.println(i +":");
// Print pile i (as shown in the project specification
// ... to be completed
}
}
}
so it prints
Piles : Blocks
0 : 0
1 : 1
2 : 2
3 : 3
4 : 4
any help would be great sorry about being sooo plain with words im new to java
Message was edited by:
JohnnyMac
[1445 byte] By [
JohnnyMaca] at [2007-10-3 3:32:37]

where are the blocks to be added?
> for (int i = 0; i < NPILES; i++) {
Add the blocks here
>}
>
> for (int i = 0; i < NPILES; i++) {
> System.out.println(i +":");
> // Print pile i (as shown in the project
> specification
> // ... to be completed
>}
> }
should have another loop inside the for-loop to print all values in the block at position i in the pile
>thats how far ive come
>for (int i = 0; i < NPILES; i++) {
>Pile pile = new Pile();
>Block block = new Block(i);
>}
>}
what is supposed to be in the blocks since they are supposed to be arraylists?
>Block block = new Block(i);
do you really want to pass i in the constructor for Block?
do you know how many blocks you are supposed to create or are getting the blocks from somewhere?
> you have the same amount of blocks as u do piles
I see.
(for int i = 0;i < piles.length;i++) {
System.out.println("Pile"+i);
for(int j = 0;j < pile[i].length;j++) {
System.out.println(""+block.get(j));
}
}
for(int j = 0; j < pile.length;j++) {
error returns cannot find symbol variable pile
for (int i = 0; i < piles.length;i++) {
System.out.println("Pile"+i);
for(int j = 0; j < pile.length;j++) {
System.out.println(""+block.get(j));
}
}
Hey JonnyMac, we are only trying to help you do the programming
sorry about the variable name error i was only trying to show you how to print values from an array of arraylists. (i am not justifying the error however).
change everywhere else in the code to the proper spelling
what does the error say now
Message was edited by:
r035198x