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 4 of 4

Thread: How to display each score in a competition?

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default How to display each score in a competition?

    I need to output the results for a diving competition. Like this

    Round 1: Round 2: Round 3: TotalScore:

    Name 1: 3 3 3 45 (made up number)
    Name 2: 4 5 3 43
    Name 3: 5 3 4 43

    Where it shows the total score for each round all added up to form the total score.

    I need to use a two dimensional array for this but don't know what the two dimensional array is....

    Id really appreciate and thank everyone who can help me....



    public class Summativerewrite
    {
        final static int Judges = 3; // max number of judges - 8
        final static int Rounds = 2; // max number of rounds - 10
     
     
        static void readfile (String[] Names, String[] School, String[] Division, int[] count) throws IOException
        {
            String line = null;
            BufferedReader reader = new BufferedReader (new FileReader ("Diving.txt"));
     
            while ((line = reader.readLine ()) != null) // might have to copy this one down
            {
                Names [count [0]] = (line);
                line = reader.readLine ();
                School [count [0]] = (line);
                line = reader.readLine ();
                Division [count [0]] = (line);
                count [0]++;
            }
     
        }
     
     
        static void Competition (String[] Names, String[] School, String[] Division, int[] count, double[] score, double[] total) throws IOException
        {
            BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
            DecimalFormat df = new DecimalFormat ("#.##");
     
            double degree;
     
            System.out.println ("Entries:");
            System.out.println ();
     
            for (int i = 0 ; i < count [0] ; i++)
            {
                System.out.println (Names [i]);
                System.out.println (School [i]);
                System.out.println (Division [i]);
                System.out.println ();
            }
            ///////////////////////////////////
     
     
            for (int r = 1 ; r <= Rounds ; r++) // indicates what round it is based on the final int
            {
                System.out.println ();
                System.out.println (" Round " + r);
                System.out.println ("-----------------------------------------------------------------------------------");
                System.out.println ();
     
     
     
     
                for (int c = 0 ; c <= count [0] - 1 ; c++)
                {
                    System.out.println ();
                    System.out.println (Names [c] + ". It is your turn"); 
                    System.out.println ();
     
                    System.out.println ("What is the degree of difficulty from 1 - 3.5?");
                    degree = Double.parseDouble (stdin.readLine ());
     
                    double max = 1;
                    double min = 10;
                    total [0] = 0;
     
                    for (int j = 1 ; j <= Judges ; j++) // 3 judges
                    {
     
                        System.out.print ("Judge" + j + ". What do you rate the following contestant? ");
                        score [0] = Double.parseDouble (stdin.readLine ());
     
                        total [0] = +score [0];
     
                        for (int k = 0 ; k < count [0] ; k++)
                        {
     
                            if (score [0] > max)
                            {
                                max = score [0];
     
                            }
     
                            if (score [0] < min)
                            {
                                min = score [0];
                            }
                        }
                    }
     
     
                    total [0] = total [0] - (max + min);
                    total [0] = total [0] * degree;   
                    System.out.println ("Max is " + max + " and min is " + min);
                    System.out.println ("Your total " + Names [c] + " is " + total [0]);
                }
     
            }
     
     
     
     
            ///////////////////////////////////
     
        }
     
     
        static void Results (String[] Names, String[] School, String[] Division, int[] count, double[] score, double[] total) throws IOException
        {
     
            System.out.println ();
            System.out.println (" Results ");
            System.out.println ("-----------------------------------------------------------------------------------");
            System.out.println ();
     
            for (int i = 1 ; i <= Rounds ; i++) // 4 should be Rounds
            {
                System.out.print ("    Round " + i + "\t");
                for (int j = 0 ; j <= 3 ; j++)
                {
                    System.out.println (Names [j]);
                    System.out.print (total [0]);
     
     
     
     
     
                }
            }
        }
     
     
        public static void main (String str[]) throws IOException
        {
            BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
     
            // variables
     
            int MAX = 99; // maximum entries allowed
     
            String[] Names = new String [MAX];
            String[] School = new String [MAX];
            String[] Division = new String [MAX];
            int[] count = {0};
     
            double[] score = new double [MAX]; // from 1 - 10
            // double[] degree = new double [MAX]; // from 1 - 3.5
            double[] total = new double [MAX]; // score * degree
     
     
     
            readfile (Names, School, Division, count);
            Competition (Names, School, Division, count, score, total);
            Results (Names, School, Division, count, score, total);
     
     
     
        }
    }


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: How to display each score in a competition?

    You don't know what 2D array to use or you don't know what one is?

    A 2D array is an array of arrays.

    A 5 by 5 2D int array looks like this

    int[][] twoD = new int[5][5];

    And if you're going through it with a for loop, say to initialize the array, do something like this

    for (int i =0; i < twoD.length; i++)
    {
    for (int j =0; j < twoD[i].length; j++)
    {
    twoD[i][j] = 5;

    }

    }

    That makes a 2D array with all values initialized to 5.

    The first part of the loop goes through the array of arrays and the second part goes through each index of those array of arrays.

    Assuming you've done 1D arrays, assume that the first part is an array of 1D arrays and that first for loop is going through that array.

    The second part is going through each index of each of the 1D arrays it encounters in that array of arrays.


    Where do you need a 2D array exactly?

    Also, any reason why you are only using the first index of each array, i.e. count[0], total[0], Names[0], etc ?
    Last edited by javapenguin; May 26th, 2012 at 03:02 PM.

  3. The Following User Says Thank You to javapenguin For This Useful Post:

    seaofFire (May 26th, 2012)

  4. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to display each score in a competition?

    I need a 2D array for the total score for each competitor. I just dont know how to display the scores and the totals for each round. Id really appreciate if you can help me. I know what 2D arrays are. I just dont know where to implement them.

    And can you please help me code it or lead me to the right direction. Im using the first index of the array because Im clueless.

  5. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: How to display each score in a competition?

    Round 1: Round 2: Round 3: TotalScore:

    Name 1: 3 3 3 45 (made up number)
    Name 2: 4 5 3 43
    Name 3: 5 3 4 43
    Not 100% sure if this is what you were getting at, but it seems that you have a bunch of names and it has 4 sets, 3 for the rounds and one for the total.

    Each name has 4 groups and there are three names, or so I'm guessing from your tidbit at the beginning.

    Represent each name as an array and have each array store the four things it needs.

    int[][] nameRecords = new int[3][4];

    nameRecords[0][0] = 3;
    nameRecords[0][1] = 3;
    nameRecords[0][2] = 3;
    nameRecords[0][3] = 45;
    nameRecords[1][0] = 4;
    nameRecords[1][1] = 5;
    nameRecords[1][2] = 3;
    nameRecords[1][3] = 43;
    nameRecords[2][0] = 5;
    nameRecords[2][1] = 3;
    nameRecords[2][2] = 4;
    nameRecords[2][3] = 43;


    Also, I noticed that you were passing an array as a parameter and then modifying its first value over and over.

    Also, you are incrementing the value of count[0] each time.

    What is the count array for?

    It only has the 0th index. I see why you are always incrementing that one. But why use an entire array for just one index?

    Assuming that you are using it as an incrementer, then you are indeed changing each index of the array, which is fine.

    You have me a bit confused, unless you're using the rounds as an index value, in which case that would work, otherwise why is it set to the final value of 2 when there are three rounds?

    index 3 would be the total, which I'm not sure how you're getting that, as those first 3 numbers aren't adding up to those totals at all.

    At least for your little tidbit at the very beginning of this post.

    Oh. Totals is made up. I just noticed that now.

    Assuming totals is round1 score + round2 score + round3 score, and I've no clue how the judges factor into this yet, but

    for (int i = 0; i < nameRecords.length; i++)
    {

    int totals = 0;

    for (int j =0; j < nameRecords[i].length; j++)
    {

    totals = totals + nameRecords[i][j];

    }

    nameRecords[i][nameRecords[i].length -1] = totals;

    }
    Last edited by javapenguin; May 26th, 2012 at 07:51 PM.

Similar Threads

  1. ROBOTIX 2011:Robotics competition in India
    By roobokgp in forum The Cafe
    Replies: 2
    Last Post: November 21st, 2013, 06:21 AM
  2. Dice score program
    By ksahakian21 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 23rd, 2012, 06:25 PM
  3. Replies: 2
    Last Post: June 8th, 2010, 03:14 PM
  4. Help with score board!
    By vlan in forum Java Applets
    Replies: 0
    Last Post: June 2nd, 2010, 05:34 AM
  5. Replies: 4
    Last Post: June 5th, 2009, 07:11 AM