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: Judging

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Judging

    Help please! I've been trying to make this work for a while. The problem is such:

    Write a program that allows the user to enter eight judges' scores and then outputs the points received by the contestant. Format your output with two decimal places. A judge awards points between 1 and 10, with 1 being the lowest and 10 being the highest. For example, if the scores are 9.2, 9.3, 9.0, 9.9, 9.5, 9.5, 9.6, and 9.8, the contestant receives a total of 56.90.

    I believe that I have nearly completed everything correctly. What I can't figure out is how to calculate the sum of the remaining 6 numbers of the Array which is assigned the variable total in the calculateScore method and retrieve the variable. My last print statement is supposed to read ("The score of "+contestant+" is "+total+":"). Not sure how to correctly call the method calculateScore or where to put the print message without receiving the error:cannot find symbol - variable contestant

    import java.util.Scanner;
    import javax.swing.*;
    public class Judging
    {
        public static void main(String[]args)//void, returns nothing
        {
            Scanner console = new Scanner (System.in);
            String contestant;
            double []scores = new double[8];
            int n = 8;
     
            do
            {
                System.out.println("What is the name of the contestant? ");
                contestant= console.nextLine();
     
                getData(scores,n,console);
     
     
            }
            while(true);
     
        }    
        private static void getData(double []scores, int n, Scanner console)
        {   
     
            double judge;
            for(int i=0;i<n;i++)
            {
                do
                {
                    System.out.print("Give the score for the judge number "+(i+1)+": ");
                    judge = console.nextDouble();
     
     
     
     
                if (judge < 1 || judge > 10)
                    System.out.println("Sorry!  The score must be between 1 and 10");
     
                else
                   scores[i] = judge;
                }
                while (judge < 1 || judge > 10);
                }
                    console.nextLine();
     
     
     
         }
     
        private static double calculateScore(double []scores, int n)
        {
                double minValue = scores[0];
                double maxValue = scores[0];
                double total = 0.00;
     
     
                if (scores[n] < minValue) 
                {
                    minValue = scores[n];
                }
                if (scores[n] > maxValue) 
                {
                    maxValue = scores[n];
                }
     
     
     
            for (int i = 0; i < 8; i++) 
            {
                if (scores[n] != minValue && scores[n] != maxValue) 
                {
                    total = total + scores[n];
     
                    //System.out.println("The score of "+contestant+"is "+total+":");?????
                }
            }
     
            return total;
     
     
        }
     
    }
    Last edited by helloworld922; April 15th, 2010 at 10:15 PM.


  2. #2
    Junior Member
    Join Date
    Feb 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Judging

    I figured this out. Thanks.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Judging

    Quote Originally Posted by gradstudent View Post
    I figured this out. Thanks.
    Good work
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers