mercredi 25 novembre 2015

if else statement for ranking and time

Currently i can output the ranking for the top 10 player, i can store the ranking inside the database while the player time is faster than the player in the database. So now, if the player time more than database player, it can print "You not in the Top 10 fastest time.\n\nCurrent Ranking of Players", it keep printing "You have also made it to the Top 10 fastest time.\n\nCurrent Ranking of Players" i no idea which line is wrong.

if (PI.getSize() == 0) {
        PI.add(player);
        System.out.println("You have also made it to the Top 10 fastest time.\n\nCurrent Ranking of Players");
        PI.display();
    } else {
        int pos;
        pos = PI.compareTo(player);
        if (pos >= PI.getSize()) {
            /**********Problem here********************/
            System.out.println("You not in the Top 10 fastest time.\n\nCurrent Ranking of Players");
            PI.display();
           /**********Problem here********************/
        }
        else if (pos != -1) {
            PI.insertAtPos(player, pos);
            System.out.println("You have also made it to the Top 10 fastest time.\n\nCurrent Ranking of Players");
            PI.display();
        } else if (pos == -1 && PI.getSize() <= 10) {
            PI.add(player);
            System.out.println("You have also made it to the Top 10 fastest time.\n\nCurrent Ranking of Players");
            PI.display();
        }
    }

output

 CONGRATULATIONS Player dgfdfe ! You have completed the Luminous Race Game in 0 minutes 29 seconds..
 You have also made it to the Top 10 fastest time.

 Current Ranking of Players
     1.  Player Ken: 0 minutes 11 seconds.
     2.  Player Hello: 0 minutes 13 seconds.
     3.  Player Wooi: 0 minutes 13 seconds.
     4.  Player Kimochi: 0 minutes 13 seconds.
     5.  Player Liang Jie: 0 minutes 15 seconds.
     6.  Player Jia Xin: 0 minutes 16 seconds.
     7.  Player Kw Kw: 0 minutes 16 seconds.
     8.  Player zhe: 0 minutes 24 seconds.
     9.  Player 1: 0 minutes 25 seconds.
     10.  Player jacob: 0 minutes 26 seconds.

The output below shows the player not faster than the player in database, but it print "You are in the top 10 fastest time"

Aucun commentaire:

Enregistrer un commentaire