Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DivingScores
- {
- public static void main(String[] args)
- {
- Scanner key = new Scanner(System.in);
- String [] judge = new String[7];
- for(int x = 0; x < judge.length; x++)
- {
- System.out.println("Enter a judge name : ");
- judge[x] = key.nextLine();
- }
- String [] diver = new String[4];
- for(int y = 0; y < diver.length; y++)
- {
- System.out.println("Enter a diver name : ");
- diver[y] = key.nextLine();
- }
- double [] diveDifficulty = new double[7];
- double diff = 0.0;
- for(int z = 0; z < diveDifficulty.length; z++)
- {
- System.out.println("Enter dive difficulty #" + (z + 1) + " : ");
- diff = key.nextDouble();
- while(true)
- if(diff >= 1.2 && diff <= 3.8)
- {
- diveDifficulty[z] = diff;
- break;
- }
- else
- {
- System.out.println("Invalid Input, Difficulty must be between 1.2 and 3.8");
- System.out.println("Enter another dive difficulty : ");
- diff = key.nextDouble();
- }
- }
- double [][] diverScore = new double[4][7];
- double score = 0.0;
- for(int a = 0; a < diverScore.length; a++)
- {
- for(int b = 0; b < diverScore[a].length; b++)
- {
- System.out.println("Enter a score for diver " + diver[a] + " : ");
- score = key.nextDouble();
- while(true)
- if(score >= 0 && score <= 10)
- {
- diverScore[a][b] = score;
- break;
- }
- else
- {
- System.out.println("Invalid Input, Score must be between 0 and 10");
- System.out.println("Enter another score : ");
- score = key.nextDouble();
- }
- }
- }
- System.out.println();
- System.out.println("judge");
- String jstring = "[";
- for(int x = 0; x < judge.length; x++)
- {
- if(x != judge.length-1)
- jstring += judge[x] + ", ";
- else
- jstring += judge[x];
- }
- jstring += "]";
- System.out.println(jstring);
- System.out.println("\ndiver");
- String dstring = "[";
- for(int y = 0; y < diver.length; y++)
- {
- if(y != diver.length-1)
- dstring += diver[y] + ", ";
- else
- dstring += diver[y];
- }
- dstring += "]";
- System.out.println(dstring);
- System.out.println("\ndiveDifficulty");
- String dfstring = "[";
- for(int z = 0; z < diveDifficulty.length; z++)
- {
- if(z != diveDifficulty.length-1)
- dfstring += diveDifficulty[z] + ", ";
- else
- dfstring += diveDifficulty[z];
- }
- dfstring += "]";
- System.out.println(dfstring);
- System.out.println();
- diverScore = findSmallest(diverScore);
- diverScore = findLargest(diverScore);
- System.out.println("diverScore");
- for(int x = 0; x < diverScore.length; x++)
- {
- System.out.print(diver[x]);
- System.out.println();
- for(int y = 0; y < diverScore[x].length; y++)
- {
- System.out.print(diverScore[x][y] + " ");
- }
- System.out.println();
- System.out.println();
- }
- double [] totScores = calcScore(diverScore, diveDifficulty, diver.length);
- awardMedal(totScores, diver);
- }
- public static double [][] findSmallest(double [][] diverScore)
- {
- double num = 0.0;
- for(int x = 0; x < diverScore.length; x++)
- {
- num = diverScore[x][0];
- for(int y = 0; y < diverScore[x].length; y++)
- {
- if(num > diverScore[x][y])
- {
- num = diverScore[x][y];
- }
- }
- for(int a = 0; a < diverScore[x].length; a++)
- {
- if(num == diverScore[x][a])
- {
- diverScore[x][a] = 0;
- break;
- }
- }
- }
- return diverScore;
- }
- public static double [][] findLargest(double [][] diverScore)
- {
- double num = 0.0;
- for(int x = 0; x < diverScore.length; x++)
- {
- num = diverScore[x][0];
- for(int y = 0; y < diverScore[x].length; y++)
- {
- if(num < diverScore[x][y])
- {
- num = diverScore[x][y];
- }
- }
- for(int b = 0; b < diverScore[x].length; b++)
- {
- if(num == diverScore[x][b])
- {
- diverScore[x][b] = 0;
- break;
- }
- }
- }
- return diverScore;
- }
- public static double [] calcScore(double [][] diverScore, double [] diveDifficulty, int diverNum)
- {
- double [] totScores = new double [diverNum];
- double dscore = 0.0;
- for(int x = 0; x < diverScore.length; x++)
- {
- for(int y = 0; y < diverScore[x].length; y++)
- {
- dscore+= diverScore[x][y] * diveDifficulty[y];
- }
- totScores[x] = dscore;
- dscore = 0.0;
- }
- return totScores;
- }
- public static void awardMedal(double [] totScores, String [] diver)
- {
- double num = totScores[0];
- for(int x = 0; x < totScores.length; x++)
- {
- if(num < totScores[x])
- num = totScores[x];
- }
- String gold = "Gold";
- for(int y = 0; y < totScores.length; y++)
- {
- if(num == totScores[y])
- {
- System.out.printf("%-20s\t%-6.2f\t%s",diver[y],totScores[y],gold);
- totScores[y] = 0;
- }
- }
- System.out.println();
- double num1 = totScores[0];
- for(int x = 0; x < totScores.length; x++)
- {
- if(num1 < totScores[x])
- num1 = totScores[x];
- }
- String silver = "Silver";
- for(int y = 0; y < totScores.length; y++)
- {
- if(num1 == totScores[y])
- {
- System.out.printf("%-20s\t%-6.2f\t%s",diver[y],totScores[y],silver);
- totScores[y] = 0;
- }
- }
- System.out.println();
- double num2 = totScores[0];
- for(int x = 0; x < totScores.length; x++)
- {
- if(num2 < totScores[x])
- num2 = totScores[x];
- }
- String bronze = "Bronze";
- for(int y = 0; y < totScores.length; y++)
- {
- if(num2 == totScores[y])
- {
- System.out.printf("%-20s\t%-6.2f\t%s",diver[y],totScores[y],bronze);
- totScores[y] = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement