This program is model after The International Gymnastics Federation using a scor
ID: 3624745 • Letter: T
Question
This program is model after The International Gymnastics Federation using a scoring system for men’s
and women’s artistic gymnastics. The system incorporates credit for the routines difficulty and
execution. The Execution and Difficulty Score is calculated by averaging the middle three of five scores.
The Execution and Difficulty Score after average are added together for final score. The Execution and
Difficulty score are between 0-5.
This program will print out direction for program and title. The program should intake 5 judges score for
Execution and Difficulty. You will need to use a for loop to intake 5 judges score, and do until scores are
within range. Remember you have Execution and Difficulty scores that must be within range. If the user
enters Execution score wrong, they must reenter score again and came not continue until score is
corrected. The same will be true for Difficulty score. Use the BubbleSort to sort scores for Execution
and Difficulty. Them use a print() method to print results. One of the last steps in the program is to
calculate average of middle three scores for both Execution and Difficulty and print out the Overall Total
Score, by adding the average of the scores.
Explanation / Answer
public static void main(String[] args)
{
//This program will print out direction for program and title.
System.out.println("The International Gymnastics Federation scoring");
System.out.println(" Enter judge scores.");
//The program should intake 5 judges score for Execution and Difficulty.
double[] executionScores = new double[5];
double[] difficultyScores = new double[5];
// You will need to use a for loop to intake 5 judges score, and do until scores are within range. Remember you have Execution and Difficulty scores that must be within range. If the user enters Execution score wrong, they must reenter score again and came not continue until score is corrected. The same will be true for Difficulty score.
Scanner kb = new Scanner(System.in);
for(int i = 0; i < 5; i++)
{
do
{
System.out.print("Enter execution score "+(i+1)+" [0-5]: ");
executionScores[i] = kb.nextDouble();
}
while(executionScores[i] < 0 || executionScores[i] > 5);
do
{
System.out.print("Enter difficulty score "+(i+1)+" [0-5]: ");
difficultyScores[i] = kb.nextDouble();
}
while(difficultyScores[i] < 0 || difficultyScores[i] > 5);
}
// Use the BubbleSort to sort scores for Execution and Difficulty.
bubbleSort(executionScores);
bubbleSort(difficultyScores);
// Then use a print() method to print results.
System.out.println(" Execution scores: "+Arrays.toString(executionScores));
System.out.println("Difficulty scores: "+Arrays.toString(difficultyScores));
// One of the last steps in the program is to calculate average of middle three scores for both Execution and Difficulty and print out the Overall Total Score, by adding the average of the scores.
double executionAverage = (executionScores[1]+executionScores[2]+executionScores[3])/3;
double difficultyAverage = (difficultyScores[1]+difficultyScores[2]+difficultyScores[3])/3;
double overall = executionAverage + difficultyAverage;
System.out.println("Overall total: "+overall);
}
public static void bubbleSort(double[] array)
{
for(int i = 0; i < array.length; i++)
{
boolean swaps = false;
for(int j = 1; j < array.length; j++)
{
if(array[j-1] > array[j])
{
double temp = array[j-1];
array[j-1] = array[j];
array[j] = temp;
swaps = true;
}
}
if(!swaps)
{
break;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.