Advertisement
Guest User

123

a guest
Jan 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.46 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class DivingScores
  4. {
  5. public static void main(String[] args)
  6. {
  7. Scanner key = new Scanner(System.in);
  8. String [] judge = new String[7];
  9. for(int x = 0; x < judge.length; x++)
  10. {
  11. System.out.println("Enter a judge name : ");
  12. judge[x] = key.nextLine();
  13. }
  14. String [] diver = new String[4];
  15. for(int y = 0; y < diver.length; y++)
  16. {
  17. System.out.println("Enter a diver name : ");
  18. diver[y] = key.nextLine();
  19. }
  20. double [] diveDifficulty = new double[7];
  21. double diff = 0.0;
  22. for(int z = 0; z < diveDifficulty.length; z++)
  23. {
  24. System.out.println("Enter dive difficulty #" + (z + 1) + " : ");
  25. diff = key.nextDouble();
  26. while(true)
  27. if(diff >= 1.2 && diff <= 3.8)
  28. {
  29. diveDifficulty[z] = diff;
  30. break;
  31. }
  32. else
  33. {
  34. System.out.println("Invalid Input, Difficulty must be between 1.2 and 3.8");
  35. System.out.println("Enter another dive difficulty : ");
  36. diff = key.nextDouble();
  37. }
  38. }
  39. double [][] diverScore = new double[4][7];
  40. double score = 0.0;
  41. for(int a = 0; a < diverScore.length; a++)
  42. {
  43. for(int b = 0; b < diverScore[a].length; b++)
  44. {
  45. System.out.println("Enter a score for diver " + diver[a] + " : ");
  46. score = key.nextDouble();
  47. while(true)
  48. if(score >= 0 && score <= 10)
  49. {
  50. diverScore[a][b] = score;
  51. break;
  52. }
  53. else
  54. {
  55. System.out.println("Invalid Input, Score must be between 0 and 10");
  56. System.out.println("Enter another score : ");
  57. score = key.nextDouble();
  58. }
  59. }
  60. }
  61. System.out.println();
  62. System.out.println("judge");
  63. String jstring = "[";
  64. for(int x = 0; x < judge.length; x++)
  65. {
  66. if(x != judge.length-1)
  67. jstring += judge[x] + ", ";
  68. else
  69. jstring += judge[x];
  70. }
  71. jstring += "]";
  72. System.out.println(jstring);
  73. System.out.println("\ndiver");
  74. String dstring = "[";
  75. for(int y = 0; y < diver.length; y++)
  76. {
  77. if(y != diver.length-1)
  78. dstring += diver[y] + ", ";
  79. else
  80. dstring += diver[y];
  81. }
  82. dstring += "]";
  83. System.out.println(dstring);
  84. System.out.println("\ndiveDifficulty");
  85. String dfstring = "[";
  86. for(int z = 0; z < diveDifficulty.length; z++)
  87. {
  88. if(z != diveDifficulty.length-1)
  89. dfstring += diveDifficulty[z] + ", ";
  90. else
  91. dfstring += diveDifficulty[z];
  92. }
  93. dfstring += "]";
  94. System.out.println(dfstring);
  95. System.out.println();
  96. diverScore = findSmallest(diverScore);
  97. diverScore = findLargest(diverScore);
  98. System.out.println("diverScore");
  99. for(int x = 0; x < diverScore.length; x++)
  100. {
  101. System.out.print(diver[x]);
  102. System.out.println();
  103. for(int y = 0; y < diverScore[x].length; y++)
  104. {
  105. System.out.print(diverScore[x][y] + " ");
  106. }
  107. System.out.println();
  108. System.out.println();
  109. }
  110. double [] totScores = calcScore(diverScore, diveDifficulty, diver.length);
  111. awardMedal(totScores, diver);
  112. }
  113. public static double [][] findSmallest(double [][] diverScore)
  114. {
  115. double num = 0.0;
  116. for(int x = 0; x < diverScore.length; x++)
  117. {
  118. num = diverScore[x][0];
  119. for(int y = 0; y < diverScore[x].length; y++)
  120. {
  121. if(num > diverScore[x][y])
  122. {
  123. num = diverScore[x][y];
  124. }
  125. }
  126. for(int a = 0; a < diverScore[x].length; a++)
  127. {
  128. if(num == diverScore[x][a])
  129. {
  130. diverScore[x][a] = 0;
  131. break;
  132. }
  133. }
  134. }
  135. return diverScore;
  136. }
  137. public static double [][] findLargest(double [][] diverScore)
  138. {
  139. double num = 0.0;
  140. for(int x = 0; x < diverScore.length; x++)
  141. {
  142. num = diverScore[x][0];
  143. for(int y = 0; y < diverScore[x].length; y++)
  144. {
  145. if(num < diverScore[x][y])
  146. {
  147. num = diverScore[x][y];
  148. }
  149. }
  150. for(int b = 0; b < diverScore[x].length; b++)
  151. {
  152. if(num == diverScore[x][b])
  153. {
  154. diverScore[x][b] = 0;
  155. break;
  156. }
  157. }
  158. }
  159. return diverScore;
  160. }
  161. public static double [] calcScore(double [][] diverScore, double [] diveDifficulty, int diverNum)
  162. {
  163. double [] totScores = new double [diverNum];
  164. double dscore = 0.0;
  165. for(int x = 0; x < diverScore.length; x++)
  166. {
  167. for(int y = 0; y < diverScore[x].length; y++)
  168. {
  169. dscore+= diverScore[x][y] * diveDifficulty[y];
  170. }
  171. totScores[x] = dscore;
  172. dscore = 0.0;
  173. }
  174. return totScores;
  175. }
  176. public static void awardMedal(double [] totScores, String [] diver)
  177. {
  178. double num = totScores[0];
  179. for(int x = 0; x < totScores.length; x++)
  180. {
  181. if(num < totScores[x])
  182. num = totScores[x];
  183. }
  184. String gold = "Gold";
  185. for(int y = 0; y < totScores.length; y++)
  186. {
  187. if(num == totScores[y])
  188. {
  189. System.out.printf("%-20s\t%-6.2f\t%s",diver[y],totScores[y],gold);
  190. totScores[y] = 0;
  191. }
  192. }
  193. System.out.println();
  194. double num1 = totScores[0];
  195. for(int x = 0; x < totScores.length; x++)
  196. {
  197. if(num1 < totScores[x])
  198. num1 = totScores[x];
  199. }
  200. String silver = "Silver";
  201. for(int y = 0; y < totScores.length; y++)
  202. {
  203. if(num1 == totScores[y])
  204. {
  205. System.out.printf("%-20s\t%-6.2f\t%s",diver[y],totScores[y],silver);
  206. totScores[y] = 0;
  207. }
  208. }
  209. System.out.println();
  210. double num2 = totScores[0];
  211. for(int x = 0; x < totScores.length; x++)
  212. {
  213. if(num2 < totScores[x])
  214. num2 = totScores[x];
  215. }
  216. String bronze = "Bronze";
  217. for(int y = 0; y < totScores.length; y++)
  218. {
  219. if(num2 == totScores[y])
  220. {
  221. System.out.printf("%-20s\t%-6.2f\t%s",diver[y],totScores[y],bronze);
  222. totScores[y] = 0;
  223. }
  224. }
  225. }
  226.  
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement