Results 1 to 11 of 11
  1. #1
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Need assistance with last step in a Program.

    Java Code:
    import java.io.*;
    import java.util.Scanner; 
    
    public class Tournament
    {
    public static void main(String[] args)throws IOException
    {
       Scanner keyboard = new Scanner(System.in); 
       
       int numOfTeams; 
       String team;
       int wins;    
       int count = 0;
       int lowestIndex = 0; 
       int highestIndex = 0;
       int largest; 
       int lowest; 
       
       System.out.print("How many teams are playing in the tournament? ");
       numOfTeams = keyboard.nextInt(); 
           
      while (numOfTeams !=2 && numOfTeams!=4 && numOfTeams !=8 && numOfTeams !=16 && numOfTeams !=32 && numOfTeams !=64)
      {
          System.out.println("You have entered an invalid number of teams. Please try again."); 
          System.out.println("What is the number of teams in the tournament?");
    	   numOfTeams = keyboard.nextInt();
      }            
              // declare array to store objects
            Teams[] tournament = new Teams[numOfTeams];
            
            do
            {
    	       // input team name and number of wins	
              System.out.println("Enter a team name: "); 
              team = keyboard.next(); 
          
              System.out.println("How many wins did that team have? ");
              wins = keyboard.nextInt();
             
              tournament[count]= new Teams(team, wins);
    	       count++;
           	 
              // end do
              }while (count < numOfTeams);
              
           for(int i=0; i<tournament.length; i++)
           {
             System.out.println("Team: " + tournament[i].getTeamName() + " with " 
             + tournament[i].getWins()+ " wins"); 
           }
           
           System.out.println(" "); 
           System.out.println("Tournament match ups: ");     
    }
    }
    
    class Teams
    {
       private String teamName;
       private int wins;
    
       // Constructor to initialize instance fields
       public Teams(String teamName, int wins)
       {
          this.teamName = teamName;
          this.wins = wins; 
       }
       
       public String getTeamName()
       {
          return teamName; 
       }
    
       public int getWins()
       {
          return wins; 
       }
    }
    Okay so for my class we were supposed to create a program that prompts the user to enter the number of teams
    in a tournament along with their names and number of wins. It is also mentioned that the wins will be entered from
    highest to lowest so sorting them won't be necessary.

    The information the user inputs is then stored in object arrays.
    I've done that much and the output looks something like this now after the user is done inputting information.

    Team: UNCC with 30 wins
    Team: GT with 15 wins;
    Team: UNC with 12 wins
    Team: UVA with 8 wins
    etc...(it changes depending on the input)

    So now I need to match the teams for the tournament, I have to match the team with the most wins with the team with the least wins
    and then the team with the second most wins with the team with the second least wins etc.

    So my output for the matches needs to look something like this:
    Game 1: UNCC Vs. UVA
    Game 2: GT Vs. UNC

    I am not sure how to do this and need assistance. It's the last step with this program and then I'm done!

    Any help will be appreciated. Thanks!
    Last edited by Steffer_Neffer_15; 11-10-2013 at 05:16 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Need assistance with last step in a Program.

    How would you do this if you were using a paper and pencil and had a list of teams written down in some order on the paper?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Re: Need assistance with last step in a Program.

    I tried doing what you suggested but I am still completely stuck. I was only able to get the teams with the most wins and least wins.
    I don't know how to continue down and match the second most wins with the second least wins and then the third most wins with the third least wins etc...

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Need assistance with last step in a Program.

    I don't know how to continue down and match the second most wins with the second least wins
    Are you talking about what you did manually to solve the problem?
    Try this: Write the scores on a line in a row, high to low. Then what do you do to chose the first matchup?
    After you get the first one, where are the second ones?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Re: Need assistance with last step in a Program.

    I'm sorry, what you're suggesting just isn't helping me.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Need assistance with last step in a Program.

    You need to be able to visualize the problem to write the code to solve it.
    Say this line of numbers has the scores, high to low:
    10 8 6 5 4 1

    Starting at both ends, pick the two numbers for the first pair: 10 and 1
    now move towards the middle and pick the next pair,
    continue until you get to the middle.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Re: Need assistance with last step in a Program.

    I still have no idea how to code that though. Your logic just isn't helping me make this work. Thanks for the effort so far though.

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,090
    Rep Power
    6

    Default Re: Need assistance with last step in a Program.

    You must not be trying very hard to understand. You're not just deflecting answers until somebody starts providing you code aren't you? Then you'll be waiting a long time.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Need assistance with last step in a Program.

    Where are the scores stored? How can you access them?
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Re: Need assistance with last step in a Program.

    No I'm not deflecting answers to get code. I'd rather have suggestions using Java to describe what I should be doing. Should I do a loop? Do I need to manipulate the array in a certain way. Writing it down on paper isn't helping me at all. And YES, I did try it. Don't assume I'm lazy. I'm not.

    I've managed to separate the array into two different arrays. Say I have this

    a with 40 wins
    b with 20 wins
    c with 18 wins
    d with 13 wins

    I've managed to separate the array
    a
    b
    c
    d

    Into two arrays:
    a
    b

    and (Though I need to reverse this array)
    c
    d

    Now I need to pair them but I'm still stuck because I don't now how to load them both side by side.
    I'm still working but any other suggestions, besides writing it down on paper, would be good.

    In the end I need to output

    a vs. d
    b vs. c

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Need assistance with last step in a Program.

    how to load them both side by side.
    Are you asking how to print two Strings on the same line?
    System.out.println(string1 + " xxx " + string2); // print 2 Strings on the same line
    or
    System.out.print(string1 +" xxx "); // start the line
    System.out.println(string2); // finish the line and move to next line
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Installing WebSphere Application Server step by step
    By manideep.d132 in forum Reviews / Advertising
    Replies: 0
    Last Post: 01-23-2012, 07:35 PM
  2. Replies: 1
    Last Post: 08-18-2011, 07:47 PM
  3. Step-by-Step Billing system in Web Services
    By oneofthelions in forum Web Frameworks
    Replies: 2
    Last Post: 12-18-2009, 10:28 AM
  4. EJB3 Message driven beans step-by-step guide
    By nix123456 in forum Enterprise JavaBeans (EJB)
    Replies: 3
    Last Post: 09-28-2009, 01:29 PM
  5. Step-by-Step Tutorial: Achieve RAD with Seam+Eclipse+Tomcat
    By Techieexchange in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 11-13-2007, 07:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •