23.5k views
2 votes
In the sport of diving, seven judges award a score between 0 and 10, where each score may be a floating-point value. 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. This program must include the following methods:

User Snotyak
by
3.2k points

1 Answer

2 votes

Answer:

see explaination

Step-by-step explanation:

import java.util.Arrays;

import java.util.Scanner;

public class Diving

{

public static void main(String[] args)

{

Scanner keyboard = new Scanner(System.in);

double[] scores = new double[7];

double lowest= 11, highest= -1 ;

double sum = 0;

double difficulty=0;

double finalscore;

boolean invalid = true;

while (invalid) {

try {

System.out.println("Enter the degree of difficulty [1.2-3.8] :");

difficulty = keyboard.nextDouble();

if (difficulty > 3.8 || difficulty < 1.2) {

System.out.println("Please enter value in the range [1.2 -3.8]");

invalid = true;

} else {

invalid = false;

}

} catch (Exception ex) {

System.out.println("Invalid characters found.Try again");

}

}

for (int i = 0; i < 7; i++) {

invalid = true;

while (invalid) {

try {

System.out.println("Enter the score for judge " + (i + 1) + " : ");

scores[i] = keyboard.nextDouble();

if (scores[i] > 10 || scores[i] < 0) {

System.out.println("Please enter value in the range [0-10]");

invalid = true;

} else {

invalid = false;

}

} catch (Exception ex) {

System.out.println("Invalid characters found. Try again");

}

}

//compare with current lowest and higest and set new values

if (scores[i] > highest) {

highest = scores[i];

}

if (scores[i] < lowest) {

lowest = scores[i];

}

}

float sumOfJudgeScores = 0;

//adding scores of judges and subtracting higest and lowest

for (int i = 0; i < 7; i++)

{

sumOfJudgeScores += scores[i];

}

//subtract higest and lowest

sumOfJudgeScores -= (highest + lowest);

float overallScore = (float) (sumOfJudgeScores *difficulty * 0.6);

System.out.println("The overall score for the diver is " + overallScore);

}

}

User Koukouviou
by
3.3k points