Results 1 to 6 of 6
  1. #1
    javaStooge is offline Member
    Join Date
    Jan 2014
    Posts
    45
    Rep Power
    0

    Default Troubleshooting Parallel Array Format - Judges Scoring Contestants

    Judges are scoring divers and I need to create a table of scores for each diver given by 7 judges. In the second for statement, I want
    Java Code:
     for(int column = 0 ; column < judges[row].length ; column++)
    to be
    Java Code:
    diver[row].length
    instead of judges. Because the total number of divers would like exceed the number of judges, and I believe this is limiting the number of columns to the number of judges. When I use divers though, an error occurs, saying that "int cannot be dereferenced". Any advice?

    Java Code:
    public float inputValidScore(){
            int Num_Judges = 7;
            
            System.out.print("Enter number of contestants: " );
            int diver = input.nextInt();
            
            float [] [] judges = new float[Num_Judges] [diver];
            
            for(int row = 0 ; row < judges.length ; row++){
                for(int column = 0 ; column < judges[row].length ; column++){
                System.out.print("Judge " + row + " Score: ");
                judges [Num_Judges] [diver] = input.nextFloat(); 
                }
    *EDIT*

    The above is just a method within the rest of the code.
    Last edited by javaStooge; 02-09-2014 at 06:10 PM.

  2. #2
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default Re: Troubleshooting Parallel Array Format - Judges Scoring Contestants

    Are you intending creating the Judges as rows or columns? As long as the Diver Contestants represent the columns, each judge will have an array position for them to store a score in.

    --------------------------------------
    1 Row for Diver Name
    7 Rows for Judge Scores
    User Input x Columns for Divers Scores in Judge Arrays

    Diver & score is represented by position in array.
    --------------------------------------

    Also: Short, Self Contained, Correct (Compilable), Example
    Last edited by Dark; 02-09-2014 at 08:33 PM.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  3. #3
    javaStooge is offline Member
    Join Date
    Jan 2014
    Posts
    45
    Rep Power
    0

    Default Re: Troubleshooting Parallel Array Format - Judges Scoring Contestants

    Yes Dark, that is exactly the method I planned on using in order to store the judges scores for each diver. 7 rows by "x" columns, depending on the number of divers.
    Given that, I'm running into some issues, I will post the code below:
    Java Code:
     public static void main(String[] args){
            inputValidScore();
            
        
        }
        
        public float inputValidScore(){
            int Num_Judges = 7;
            
            System.out.print("Enter number of contestants: " );
            int diver = input.nextInt();
            
            float [] [] judges = new float[Num_Judges] [diver];
            
            for(int row = 0 ; row < judges.length ; row++){
                for(int column = 0 ; column < diver.length ; column++){  //here, diver.length does not work, why?? 
                System.out.print("Judge " + row + " Score: ");
                judges [Num_Judges] [diver] = input.nextFloat(); 
                }    
            
        }
        
        public void inputAllScores(float[] judges){
            int row = 7;
            int column = diver; 
            float [] [] allScores = new float[row] [column];
            System.out.println("Diver: ");
            System.out.print(allScores[column]);
            
        }
    For the inputAllScores method, I am using the data entered into the inputValidScores method, to create a table of scores that will be printed in the console. I would like int column to equal the number of divers,
    Java Code:
    int column = diver;
    . I was hoping this would work, but diver is not read within this method.

    *EDIT*
    Sample output:
    ...................Diver: 1 ....... 2........3 .......
    ............................___ ... ___ ... ___
    Judge 1....................5.......6.........9
    Judge 2....................8
    Judge 3....................9

    hopefully you will get the idea.
    Last edited by javaStooge; 02-09-2014 at 09:10 PM.

  4. #4
    javaStooge is offline Member
    Join Date
    Jan 2014
    Posts
    45
    Rep Power
    0

    Default Re: Troubleshooting Parallel Array Format - Judges Scoring Contestants

    Another hole in my understanding involves performing math operations on values stored within the array.

    "The highest and lowest scores are thrown out and the remaining scores are added together. The sum is then multiplied by the degree of difficulty for that dive. The degree of difficulty ranges from 1.2 to 3.8 points. The total is then multiplied by 0.6 to determine the diverís score. Write a computer program that will ultimately determine the diverís score." --directly from the assignment

    I have not started the code for this yet because I'm not sure how to have this method perform the calculations for each diver, then store and return the values for each. In order to see who is the winner of the dive contest.

  5. #5
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,058
    Rep Power
    6

    Default Re: Troubleshooting Parallel Array Format - Judges Scoring Contestants

    Are you required to use parallel arrays? If so, I hope this exercise is intended to teach you why parallel arrays are a bad idea. In fact, using arrays at all is questionable. The OO way to do this would be to give each Diver some sort of Collection of scores. (Or, depending on how you want to model it, have a Tournament class that maps Judges to Divers to scores.)
    Get in the habit of using standard Java naming conventions!

  6. #6
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default Re: Troubleshooting Parallel Array Format - Judges Scoring Contestants

    Your code doesn't compile, it is giving me some errors. Is this everything? It shows missing variables and illegal calls. Did you try to compile your program before posting it?

    Also it shows you trying to cast .length on a primitive int diver. If you are trying to get how many divers are there, you don't need to call length on it atm. As an int, it will give you an integer just from calling it.

    I have no idea if these are related to your problems, but these are problems in the code you posted that I tried to compile.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

Similar Threads

  1. Parallel Array help
    By garrettlwilson in forum New To Java
    Replies: 1
    Last Post: 10-11-2013, 08:25 PM
  2. Parallel Array Lists?
    By Solarsonic in forum New To Java
    Replies: 24
    Last Post: 05-18-2011, 05:18 AM
  3. troubleshooting
    By ahhreeyell in forum AWT / Swing
    Replies: 2
    Last Post: 03-18-2011, 02:54 AM

Posting Permissions

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