In a gymnastics or diving competition, each contestant’s score is calculated by
ID: 3572505 • Letter: I
Question
In a gymnastics or diving competition, each contestant’s score is calculated by dropping the lowest and highest scores and then adding the remaining scores. Write a Java program that allows the user to enter the number of judges (assume the number of judges can be as few as 5 and as many as 9), and prompt for each judges’ score (a judge gives a core points between 1 and 10, with 1 being the lowest and 10 being the highest.) and then outputs the points received by the contestant.
For example, if there are 8 judges and 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 points.
Requirements:
Program must be syntax error free (compiles and runs on IDE).
Write an algorithm for the program and include the algorithm in the beginning or at the end of your program as comments.
Prompt user to input information clearly with instructions to guide user entering proper data. Your program should have sufficient error checking to verify the input data, and reject the wrong data input from the user (e.g., a score less than 1 or a score greater than 10, etc.)
Use array to implement the score calculation.
Implement the score input and score calculation in user-defined methods respectively and call the methods from main program.
Explanation / Answer
import java.util.*;
public class gymnastic_drivngcompotation{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter no of Judges:");
int judges=sc.nextInt();
if(judges<5 ||judges>9){
System.out.println("Judges should be in limit 5 and 9:");
return;
}
else{ float inputdata[]=new float[judges];
float[] sc_score=new float[inputdata.length];
sc_score=score_input(inputdata);
float score_cal=score_calculation(sc_score);
//System.out.println(sc_score);
System.out.println("the contest recives a total score of:"+score_cal +" points");
}
}
public static float score_calculation(float[] sc_score) {
int total_score=0;
for(int i=0;i<sc_score.length;i++)
total_score+=sc_score[i];
return total_score;
}
public static float[] score_input(float[] inputdata) {
Scanner ss=new Scanner(System.in);
float value;
for(int i=0;i<inputdata.length;i++){
System.out.println("enter each score of judge:"+(i+1));
value=ss.nextFloat();
if(value >=1.0 && value <=10.0)
inputdata[i]=value;
else
System.out.println("score should be in 1 and 10...");
}
return inputdata;
}
}
output :if no error in input data:
enter no of Judges:
5
enter each score of judge:1
2
enter each score of judge:2
9
enter each score of judge:3
8
enter each score of judge:4
7
enter each score of judge:5
4
the contest recives a total score of:30.0 points
output if error in judges limit:
enter no of Judges:
12
Judges should be in limit 5 and 9:
output:error if scores not in limit:
enter no of Judges:
5
enter each score of judge:1
2
enter each score of judge:2
5
enter each score of judge:3
3
enter each score of judge:4
7
enter each score of judge:5
15
score should be in 1 and 10...
the contest recives a total score of:17.0 points
Alogrithm:
1.enter judges limit
2.if judsges count not in limit then program terminates
3.if judges are in limit then ask for score
4.and scores are not in limit it does not include in total
5.finally gives totalscre.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.