Scoreboard in a simple guessing game
<p>Below is the code to my guessing game.</p>

<p>I'm trying to implement a scoreboard which is shown after a player enters their name. The scoreboard is supposed to save the variables <code>playername</code>, <code>count</code> and <code>totalTime</code> as long as the application is running. </p>

<p>It is also supposed to sort by amount of guesses (lower amount of guesses = higher on scoreboard).</p>

<p>If two players had the same amount of guesses, it then sorts by which had the faster time. I've tried making an arraylist without any luck. I'm trying to get the index to increment by 1 every time the game resets, so the variables aren't overwritten by new ones.</p>

<p>I am also having trouble getting the arraylist to accept a long and string.</p>

<pre><code>import java.util. *;

class Game {        

public void start() {

    int randomNumber = (int) (Math.random() * 1000);
    int number = -1, index, count;  
    String decision, guess, playername;
    long currentTime = 0, newTime, totalTime;
    boolean quitting = false;
    count = 0;
    System.out.println("Welcome to the Guessing Game");
    System.out.println("Type \"quit\" to quit at anytime.");
    Scanner scan  = new Scanner(System.in);
    System.out.println("Try to guess the number. Range is from 1 - 1000: ");
    guess = scan.nextLine();
    if ("quit".equals(guess)) {
        System.out.println("Quitting...");
        quitting = true;
    } else {
        number = Integer.parseInt(guess);
    }

    while (number != randomNumber &amp;&amp; number &gt; -1){
        if (number &gt;= 1001 || number &lt;= 1) {
            System.out.println("Number is not between 1 - 1000. Enter another number");
        }

        if (number != randomNumber &amp;&amp; number &gt; randomNumber &amp;&amp; number &lt;= 1000 &amp;&amp; number &gt;= 1) {
            System.out.println("Number is too high. Try again!");
        }

        if (number != randomNumber &amp;&amp; number &lt; randomNumber &amp;&amp; number &lt; 1000 &amp;&amp; number &gt; 1) {
            System.out.println("Number is too low. Try again!");
        }

        if (number != randomNumber) {
            count = count + 1;
        }

        if (number != randomNumber) {
            Scanner scannew  = new Scanner(System.in);
            System.out.println("Enter a different number: ");
            guess = scannew.nextLine();
            if ("quit".equals(guess)) {
                System.out.println("Quitting...");
                quitting = true;
            } else {
                number = Integer.parseInt(guess);
            }
        }

        if (count == 1) {
            long lDateTime = new Date().getTime();
            currentTime = lDateTime / 1000;
        }

        if (quitting) {
            break;
        }
    }

    if (!quitting) {
        long DateTime = new Date().getTime();
        newTime = DateTime / 1000;
        totalTime = newTime - currentTime;

        System.out.println("You win! Your total amount of guesses was: " + count + " Total time (seconds): " + (totalTime));

        Scanner name  = new Scanner(System.in);
        System.out.println("Enter your name: ");
        playername = scan.nextLine();


        //ArrayList&lt;Integer&gt; score = new ArrayList&lt;Integer&gt;();
        //score.add(index, count);
        //System.out.println(score);
        //index++;

        Scanner decision1 = new Scanner(System.in);
        System.out.println("Do you want to play again? y/n");
        decision = decision1.nextLine();

        if ("y".equals(decision)) {
            Game one = new Game();
            one.start();
        }

        if ("n".equals(decision)) {
            System.out.println("Quitting...");
        }
    }
    scan.close();
}
}
</code></pre>
