java - LinkedList<type> filled with repeat entries -


i start table mysql filled player data scoreboard. has 4 entries different names , scores. code sucessfully retrieves these entries. tested retrieved entries using method:

while (resultset.next()) {             int id = resultset.getint("id");             string name = resultset.getstring("name");             int score = resultset.getint("score");             int lastscore = resultset.getint("lastscore");             system.out.println("" + integer.tostring(id) + ", " + name + ", $" + integer.tostring(score) + ".");             scoreboard.addscore(id, name, score); 

the println() returns following 4 lines:

1, sam, $10000. 2, jesus, $12000. 3, michael, $9000. 4, asako, $4500. 

addscore() looks this:

    public static void addscore(int id, string name, int score){//adds new score scores linkedlist         if (scores.isempty())             scores.addfirst(new player(id, name, score, 0));         (int = 0; < scores.size(); i++){             if (score > scores.get(i).getscore()){                 scores.add(i, new player(id, name, score, 0));                 return;             }         }         scores.addlast(new player(id, name, score, 0));     } 

finally, player class looks this:

public class player {     private static int id;     private static string name;     private static int score;     private static int lastposition;      public player(int id, string name, int score, int lastposition){         setid(id);         setname(name);         setscore(score);         setlastposition(lastposition);     } //... 

when around displaying scores displays this:

  1. asako $4500
  2. asako $4500
  3. asako $4500
  4. asako $4500

is there wrong code causing this? also, there code think necessary better assess question? tried put of significant code in.


while retrieving scoreboard use code scores.get(i).setlastposition(i+1);

is correct syntax? can set value of part of element in linkedlist calling get, or not possible?

you class player defines 4 static variables, means defined once entire class, no matter how many instances of player create. each new instance overwrites values, , last one, asako $4500, "wins".

remove static 4 variables in player, have 1 value each instance of player class.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -