linked list assignment

Hello, im quite new to java, and I have a problem with a piece of code.

This is the code so far, I hope u can help me with the code or with hints

Regards Tim

public class DataStructuren

{

/* STEP 1

Write the code for a method make() which creates and fills a 4 x 4 array with values such that the

array elements of myArray[j] contain the values of the expression (i+j)*(i-j)/2

*/

public void make()

{

} // end method make()

/* STEP 2

Write the code for a method singleDim() which converts the myTable array to a single dimension array

newTable with 16 elements

*/

public void singleDim()

{

} // end method singleDim()

/* STEP 3

Write the code for a method fillTree() which inserts the unique values from uniArray into a binary tree

*/

public void fillTree() // Step 3

{

// you can use methods from the Deitel & Deitel class 'tree.java'

}

/* STEP 4

Write the code to build a linked list with the sorted values from the binary tree. Take a look at the code

in Deitel & Deitel class tree.java. Add a list object and a new method to this class to build the linked list.

*/

public void buildList()

{

// call methods from tree.java

}

/* STEP 5

Write code to print the linked list (you can use the print() method from class list.java)

*/

public void listTree() // Step 5

{

}

public static void main(String args[])

{

DataStructuren toetsOpdracht = new DataStructuren();

toetsOpdracht.make();

toetsOpdracht.singleDim();

toetsOpdracht.fillTree();

toetsOpdracht.buildList();

toetsOpdracht.listTree();

}

} // end class DataStructuren

[1839 byte] By [oinkoink12a] at [2007-10-2 16:48:48]
# 1
Hi,We won't do your homework, but we can help you if you have specific questions. I checked the code, and it looks like you haven't done anything at all?Kaj
kajbja at 2007-7-13 17:59:57 > top of Java-index,Java Essentials,New To Java...
# 2
Tim, no one will do your homework for you. If you encounter a specific problem with one of these assignments, show us what you have tried, what you expect to happen, and what actually happens (be specific! post exact stack traces/error messages if you get any), .
Herko_ter_Horsta at 2007-7-13 17:59:57 > top of Java-index,Java Essentials,New To Java...
# 3
ok ok ill post the new code that ive done in a sec
oinkoink12a at 2007-7-13 17:59:57 > top of Java-index,Java Essentials,New To Java...
# 4
Use code tags! Put [code] and [/code] around your code.
pbrockway2a at 2007-7-13 17:59:57 > top of Java-index,Java Essentials,New To Java...
# 5

ok im here so far,

most of 1 is done but \ how to add the values of the expression?

public class DataStructuren

{

/* STEP 1

Write the code for a method make() which creates and fills a 4 x 4 array with values such that the

array elements of myArray[j] contain the values of the expression (i+j)*(i-j)/2

*/

public void make()

{

int b[][];

myarray = new int[ 4 ][ 4 ];

System.out.println("step 1");

} // end method make()

/* STEP 2

Write the code for a method singleDim() which converts the myTable array to a single dimension array

newTable with 16 elements

*/

public void singleDim()

{

} // end method singleDim()

/* STEP 3

Write the code for a method fillTree() which inserts the unique values from uniArray into a binary tree

*/

public void fillTree() // Step 3

{

// you can use methods from the Deitel & Deitel class 'tree.java'

}

/* STEP 4

Write the code to build a linked list with the sorted values from the binary tree. Take a look at the code

in Deitel & Deitel class tree.java. Add a list object and a new method to this class to build the linked list.

*/

public void buildList()

{

// call methods from tree.java

}

/* STEP 5

Write code to print the linked list (you can use the print() method from class list.java)

*/

public void listTree() // Step 5

{

}

public static void main(String args[])

{

DataStructuren toetsOpdracht = new DataStructuren();

toetsOpdracht.make();

toetsOpdracht.singleDim();

toetsOpdracht.fillTree();

toetsOpdracht.buildList();

toetsOpdracht.listTree();

}

} // end class DataStructuren

oinkoink12a at 2007-7-13 17:59:57 > top of Java-index,Java Essentials,New To Java...
# 6

Most of 1 is done? Come on... all you did is declare an array, and you even managed to mess that up (What do you want? b or myarray?).

You know how to assign values to an index in an array, right? You need to do this for 4 x 4 array elements.

When I see i and j, I think for-loop, and so should you. Inside the for-loop use the expression from the assignment.

Herko_ter_Horsta at 2007-7-13 17:59:57 > top of Java-index,Java Essentials,New To Java...
# 7
And yes, please use code tags around any code you post. Right now, the forum thinks [ i ] means italic.
Herko_ter_Horsta at 2007-7-13 17:59:57 > top of Java-index,Java Essentials,New To Java...
# 8
One more thing: because of the division that takes place in the expression, I don't think you want to use an int array.
Herko_ter_Horsta at 2007-7-13 17:59:57 > top of Java-index,Java Essentials,New To Java...
# 9

ok a bit of a change

public void make()

{

int myArray[][];

myArray = new int[ 4 ][ ];

myArray[ 0 ] = new int [ 4 ];

myArray[ 1 ] = new int [ 4 ];

myArray[ 2 ] = new int [ 4 ];

myArray[ 3 ] = new int [ 4 ];

System.out.println("step 1");

} // end method make()

why not use int. i use int cause u can devide it by 2 with strings u can't (thats what i learned)

oinkoink12a at 2007-7-13 17:59:57 > top of Java-index,Java Essentials,New To Java...
# 10
But what happens if you divided the int 3 by 2? You get 1.5, which isn't an int. Did you learn about floats and doubles?Also, I still don't see a for-loop, I'm pretty sure you have to use them for this part of the assignment.
Herko_ter_Horsta at 2007-7-13 17:59:57 > top of Java-index,Java Essentials,New To Java...