3 Replies - 225 Views - Last Post: 19 July 2011 - 08:27 AM Rate Topic: -----

#1 LieannM  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 18-June 11

Computing for an average using a function/method

Posted 19 July 2011 - 08:15 AM

JudgeScore theirscore = new JudgeScore();
      //------------ 1
      String [] Contnum1 = new String[5];
         String Cont1;
         System.out.println(" ");
         System.out.println(" ");
         System.out.print("\t Enter Name: ");
         Cont1 = input.nextLine();
         Contnum1[0] = Cont1;
         double [] judge1 = new double[5];
            System.out.println("Contestant #1 " + Cont1 + " : ");
            theirscore.score(judge1);
            
            double largest = theirscore.highest(judge1);
            System.out.println("Highest Score is : " + largest );
            double lowval = theirscore.lowest(judge1);
            System.out.println("The Lowest Score is : " + lowval );
            
          
 //----------------- 2
       String [] Contnum2 = new String[5];
         String Cont2;
         System.out.println(" ");
         System.out.println(" ");
         
         System.out.print("\t Enter Name: ");
         Cont2 = input.nextLine();
         Contnum2[0] = Cont2;
         
        double [] judge2 = new double[5];
            System.out.println("Contestant #2 " + Cont2 + " : ");
            theirscore.score(judge2);
            

            largest = theirscore.highest(judge2);
            System.out.println("Highest Score is : " + largest );
            lowval = theirscore.lowest(judge2);
            System.out.println("The Lowest Score is : " + lowval );


class JudgeScore{
    double[] score(double[] lima){
    Scanner scan = new Scanner(System.in);
    //double[] score = new double[5];
    
          System.out.println(" Please Enter The Score: ");
           for(int x=1;x<=5;x++)
           {
               System.out.print("\t Judge #" + x + ": ");
               lima[x-1] = scan.nextDouble();
           }
           System.out.print("\tGiven Score: ");
    for(int s=0;s<lima.length;s++)
        {
            System.out.print(" "+lima[s]);
        }
  System.out.println("");
        
        return lima;
    }
    double highest(double[] high){
     double largest = high [0];
   System.out.println("");
  
for(int e=1;e<high.length;e++)
{
    if(high[e]>largest)
        largest=high[e];
}
return largest;
}
    
    
    double lowest(double[] low){
     double lowval = low[0];
for(int e=1;e<low.length;e++)
{
    if(low[e]<lowval)
        lowval=low[e];
}
return lowval;
}
   



how will I compute the average per contestant then will rank them to determine the winner? :helpsmilie: :helpsmilie:

Is This A Good Question/Topic? 0
  • +

Replies To: Computing for an average using a function/method

#2 ipushmycar  Icon User is offline

  • D.I.C Regular

Reputation: 86
  • View blog
  • Posts: 390
  • Joined: 29-August 10

Re: Computing for an average using a function/method

Posted 19 July 2011 - 08:21 AM

Add up their scores, divide that by how many scores there are, store it (array?). Continue until you finish all the contestants, sort your data structure you used to store the averages (array), print out the averages.
Was This Post Helpful? 1
  • +
  • -

#3 LieannM  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 18-June 11

Re: Computing for an average using a function/method

Posted 19 July 2011 - 08:24 AM

how will I add their score if the scores are inside an array? :dontgetit:
Was This Post Helpful? 0
  • +
  • -

#4 ipushmycar  Icon User is offline

  • D.I.C Regular

Reputation: 86
  • View blog
  • Posts: 390
  • Joined: 29-August 10

Re: Computing for an average using a function/method

Posted 19 July 2011 - 08:27 AM

Well how do you go through an array and access each individual element?

Hint: You do it on line 65.
	            double largest = theirscore.highest(judge1);
	            System.out.println("Highest Score is : " + largest );
	            double lowval = theirscore.lowest(judge1);



Correct me if I am wrong but it seems that each contestant has two scores. You save these scores in largest and lowval. So why not create a new array called conScore which will hold the averages of all contestants. Then before you over the data the in largest and lowval find the average of the two and add them to the array. Do that for each contestant.

conScore[0] = (larges+lowval)/2;



Just remember array indexes start at 0 though. So for contestant #1 you would have to do this.

conScore[0] //This is contestant 1.


This post has been edited by ipushmycar: 19 July 2011 - 08:35 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1