*
The moose likes Beginning Java and the fly likes Method to display not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Method to display not working" Watch "Method to display not working" New topic
Author

Method to display not working

Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
Hi,

When someone has a moment could they suggest why the following method is only printing out the last entry?


Thanking you in advance!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Whats in this method:

?
[ November 24, 2004: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
Method to retrieve the Student objects from the students array
-needed to print out the student data


public Student retrieveStudent (int index)
{
return students[index];
}//end Method retrieveStudent

This is also in my Storage class.
Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
I am currently testing.

In my test file I have the following:


Currently I am getting the following:

The details entered are as follows:


Student Name: Student Course:
============= ==============+

Joe Dohn Visual C#
Joe Dohn Visual C#
Joe Dohn Visual C#
Joe Dohn Visual C#
Joe Dohn Visual C#
Joe Dohn Visual C#
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

So, it might be this method:

which is giving you a problem. What you can say with a degree of certainty is the index you access you students array with is being incremented, so it looks like the contents of this array may well be six entries of the same value. What does you Storage class look like?
Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
Paul,

GOT IT!!

I wrote one of my classes four months ago and used static for my variable.

Once I changed these my output was as expected.

Thanks for your help!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Method to display not working