Home Forums Gamescan Chat42 About
* Login   * Register * FAQ    * Search
It is currently Sun 07-27-2025 3:37AM

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: in need of java assistance
PostPosted: Thu 04-13-2006 3:33PM 
Offline
General
User avatar

Joined: Mon 09-22-2003 3:29PM
Posts: 4317
Location: Find out on irc

Source: Havener Center
yea so java sucks.. actually no linked lists suck.


so were doing a library type thing using linked lists, and to each node im adding an array. the problem is for some reason each time i add a new node it overwrites all the toher ones..

so say i add the first node with data 1, then show the data and it prints 1.

if i were to add a new node with data 2, then when i show the data it prints 2 2, and for 3 it prints 3 3 3 etc etc...

so itd be nice if someone could tell me what was wrong with my code.

public void addANodeToStart(String[] addData)
{
head = new ListNode(addData, head);
}

public void showList( )
{
ListNode position;
position = head;
while (position != null)
{
System.out.println(blagh);
position = position.link;
}
}


as far as me and my teacher and other people can tell its waht it needs to be...

if u know java good, and have some time and would like to help im at the havener info desk till bout 7.. or if you can tell me whats wrong from that excerpt thatd be great, bc i know for a fact the problem lies within those 2 classes

_________________
_______Notebook_________Gaming - Circa 2008ish
proc___T8300____________Q6600
clock-----------2.4GHz-----------
ram--------------4GB------------
vid__GF8600M GT 256MB__2xGF8800GTS 512MB sli
hdd____160GB_______3.5TBw/parity on a 3ware card


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Thu 04-13-2006 4:48PM 
Offline
Colonel
User avatar

Joined: Mon 04-15-2002 4:23PM
Posts: 516
Location: Far, far away from Rolla (Colorado to be exact)

Source: Off Campus
Post your ListNode(String[], ListNode) constructor and where/how you are using the addANodeToStart method.

_________________
That's right. I'm gone. Rolla couldn't hold me. If you are still there, I know your pain. But I'm still going to laugh at you from far, far away. :-P


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Thu 04-13-2006 5:27PM 
Offline
Colonel
User avatar

Joined: Sun 09-12-2004 8:22PM
Posts: 657
Location: somewhere

Source: Kappa Sigma
I'd imagine that his constructor looks very similar to this:
Code:
        public ListNode(String[] newData, ListNode linkValue)
        {
            data = new String[newData.length];
            for (int i=0;i<data.length-1;i++){
               data[i]=newData[i];
            }
            link = linkValue;
        }


I'd like to see the section where you make the call to addANodeToStart. I'm betting that that is where the error is going to be at since what you've shown is basically what was given by the teacher.
And why are you passing an array? According to the problem description you should be passing an object.

_________________
if you woke up as me everyday, you'd hate yourself too.


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Thu 04-13-2006 5:44PM 
Offline
General
User avatar

Joined: Mon 09-22-2003 3:29PM
Posts: 4317
Location: Find out on irc

Source: Havener Center
meh should would could, my way works for eveything except for the adding node part... and array is just as much of an object as a book object, i just dont have to write another class with getters and setters for using an array

raman check ur pm

_________________
_______Notebook_________Gaming - Circa 2008ish
proc___T8300____________Q6600
clock-----------2.4GHz-----------
ram--------------4GB------------
vid__GF8600M GT 256MB__2xGF8800GTS 512MB sli
hdd____160GB_______3.5TBw/parity on a 3ware card


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Thu 04-13-2006 10:15PM 
Offline
Colonel
User avatar

Joined: Mon 04-15-2002 4:23PM
Posts: 516
Location: Far, far away from Rolla (Colorado to be exact)

Source: Off Campus
UrLocalGuru wrote:
meh should would could, my way works for eveything except for the adding node part... and array is just as much of an object as a book object, i just dont have to write another class with getters and setters for using an array


After just a quick look and without trying anything, here is what I see. When you are adding new entries you are never creating a new string array (ie: never creating a new object which is why you are seeing x yy zzz ...You keep updating the data in the existing object and creating more references to it).

Hope that helps.

_________________
That's right. I'm gone. Rolla couldn't hold me. If you are still there, I know your pain. But I'm still going to laugh at you from far, far away. :-P


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Fri 04-14-2006 5:09PM 
Offline
Captain

Joined: Tue 06-01-2004 3:57PM
Posts: 136

Source: Off Campus
If you send me all your code I could take a look at it, I'm pretty good with Java usually.


Top
 Profile  
    
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group