Computing.Net > Forums > Programming > Tower of Hanoi (Java)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Tower of Hanoi (Java)

Reply to Message Icon

Name: Eric Williams
Date: May 27, 2006 at 18:06:39 Pacific
OS: Windows XP Home Edition S
CPU/Ram: 2.60GHz HT P4 800MHz FSB
Comment:

I'm having a little trouble with a reference to a variable created from a static method.

public class Main {

static ArrayList rings = new ArrayList();

/** Creates a new instance of Main */
public Main() {

}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
initTowers();
initRings(Integer.parseInt(JOptionPane.showInputDialog("Number of rings:")));
solve();
}

public static void initTowers(){
Tower src = new Tower(1);
Tower aux = new Tower(2);
Tower des = new Tower(3);
}

public static void initRings(int numRings){
for(int i=1; i<= numRings; i++){
rings.add(new Ring(i));
}

for(int i=numRings; i>= 1; i--){
((Ring)(rings.get(i))).moveTo(src);
}
}

public static void solve(){

}
}

The error is on this line:

((Ring)(rings.get(i))).moveTo(src);


Using Netbeans 5.0, the line creates an error that basically tells me there is no such variable src. I've tried to typecast it as a Tower, but to no avail. Any help would be greatly appreciated.

P.S. - they should really let you use the "code" tags, especially in the Programming forum.

Any help would be greatly appreciated... any help... at all... about anything... please?



Sponsored Link
Ads by Google

Response Number 1
Name: gometro33
Date: May 27, 2006 at 21:52:24 Pacific
Reply:

If you want to send me the whole NB project folder I'll take a look for you. I can't stand looking at code on the forum and I suspect there might be an error in another one of your classes.

Zip and e-mail me the project if you want.

Alert me after you respond otherwise I'll forget to come back.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Tower of Hanoi (Java)

Towers of Hanoi www.computing.net/answers/programming/towers-of-hanoi/12527.html

enforcing repaint www.computing.net/answers/programming/enforcing-repaint/8080.html

Factorial Program www.computing.net/answers/programming/factorial-program/7939.html