Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: My code is in need of some severe jazzing up

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default My code is in need of some severe jazzing up

    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);
     
    		  }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: My code is in need of some severe jazzing up

    how can I include their respective number of guesses beside their name
    I don't see where you are outputing any information.

    Add some comments like: //********* HERE I OUTPUT THE NAMES AND NUMBER OF GUESSES <<<<<<<<<<<<<

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My code is in need of some severe jazzing up

    Quote Originally Posted by Norm View Post
    I don't see where you are outputing any information.

    Add some comments like: //********* HERE I OUTPUT THE NAMES AND NUMBER OF GUESSES <<<<<<<<<<<<<
    Thank you for your reply.

    However I have just discovered the Jtable and it has solved all my problems!

    Now my output looks structured, logical and SEXY!