Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method to display not working

 
Maureen Charlton
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats in this method:

?
[ November 24, 2004: Message edited by: Paul Sturrock ]
 
Maureen Charlton
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic