Hi guys, Im hoping someone can help me with me problem. I have a variable assigned to a value
guesses = 7.
I also have a leader board of 3 people
david
daren
linda
If the user guesses a number in less guesses than the person at the top of the leaderboard then the name in position one gets replaced with the user name, etc. The output of this part of my program looks very unimpressive, simply:
david daren linda
How can I allign these names vertically?
How can I put a number beside each name? like this
1. David
2. Daren
3. Linda
and how can I include their respective number of guesses beside their name?
1. David 8
2. Daren 12
3. Linda 15
public static void leaderboard() { int leastguesses = 4; int middleguesses = 10; int mostguesses = 20; String[] content = new String[3]; content[0] = "david"; content[1] = "daren"; content[2] = "linda"; String name = JOptionPane.showInputDialog(null, "Please enter your name:", "Your name", 1); JFrame leaders = new JFrame("Leader Board"); JPanel Panel = new JPanel(); leaders.getContentPane().add(Panel, "North"); if ((guesses <= mostguesses)&&(guesses >= middleguesses)) { content[2]= name; mostguesses = guesses; } if ((guesses >= leastguesses) && (guesses <= middleguesses)) { content[2] = content[1]; content[1] = name; middleguesses = guesses; } if (guesses < leastguesses) { content[2] = content[1]; content[1] = content[0]; content[0] = name; leastguesses = guesses; } else if (guesses > mostguesses) { JOptionPane.showMessageDialog(null, "Sorry " + name + " your score was good enough to make the leader board. Better luck next time", "Failure", 1); } for (int y = 0; y < content.length; y++) { Panel.add(new JTextArea(content[y])); } leaders.pack(); leaders.setVisible(true); System.exit(0); }