Advertisement
JarrettBarnes

SkaterScores

Apr 25th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2.  
  3. public class Program {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. //Jarrett Barnes
  8. //4-25-19
  9. //Skater Scores
  10.  
  11. double [] [] scores = { {5.6, 3.5, 5.9, 5.4, 5.1},
  12. {4.4, 5.4, 5.4, 5.8, 5.9},
  13. {4.5, 2.4, 4.3, 5.2, 4.5},
  14. {4.4, 5.2, 5.8, 4.9, 5.6},
  15. {5.3, 4.2, 5.5, 4.9, 4.9},
  16. {5.9, 5.6, 0.7, 4.4, 6.0},
  17. {5.1, 5.8, 3.2, 4.9, 2.8}};
  18.  
  19. //Helps round scores to 1 decimal place
  20. DecimalFormat df = new DecimalFormat("#.0");
  21.  
  22. for(int skater = 0; skater < scores.length; skater++) {
  23. System.out.println("Scores for Skater #" + (skater + 1) + ":");
  24. double sum = 0;
  25. double min = 6;
  26. double max = 0;
  27.  
  28. for(int judge = 0; judge < scores[skater].length; judge++) {
  29.  
  30. //if lowest score
  31. if (scores [skater] [judge] < min) {
  32. min = scores [skater] [judge];
  33. }
  34.  
  35. //if highest score
  36. if (scores [skater] [judge] > max) {
  37. max = scores [skater] [judge];
  38. }
  39. sum = sum + scores[skater][judge];
  40. System.out.print(scores[skater][judge] + "\t");
  41. }
  42.  
  43. //subtract lowest and highest scores
  44. sum = sum - min - max;
  45. double avg = sum / (scores[skater].length - 2);
  46. System.out.println();
  47. System.out.println("Average: " + df.format(avg));
  48. System.out.println();
  49. min = 0;
  50. max = 0;
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement