Guest User

Untitled

a guest
Jun 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. // Lab 10
  2. // Programmer: Daniel Shen
  3. // Editor(s) used: XP Notepad
  4. // Compiler(s) used: Java 1.6.0_12
  5. //
  6.  
  7. import java.io.*;
  8. import java.util.*;
  9. import java.text.*;
  10.  
  11. public class MyList
  12. {
  13. static double getAverage(int[] score)
  14. {
  15. int sum = 0;
  16. int i = 0;
  17. for (i = 0; i < score.length; i++)
  18. sum += score[i];
  19. double average = (double)sum / score.length;
  20. return average;
  21. } // getAverage
  22.  
  23. static int countScoresGreater(int[] score, double x)
  24. {
  25. int nGreater = 0;
  26. int i; // loop counter
  27. for (i = 0; i < score.length; i++)
  28. if (score[i] >= x) nGreater++;
  29. return nGreater;
  30. } // countScoresGreater
  31.  
  32.  
  33. public static void main(String[] argv) throws Exception
  34. {
  35. BufferedReader cin;
  36. cin = new BufferedReader(new InputStreamReader(System.in));
  37.  
  38. int size;
  39. System.out.print("What is the size? ");
  40. size = new Double(cin.readLine()).intValue();
  41. int[] score = new int[size];
  42.  
  43. // read and save the scores
  44. int i;
  45. for (i = 0; i < score.length; i++)
  46. {
  47. System.out.print("Please enter score[" + i + "]: ");
  48. score[i] = new Double(cin.readLine()).intValue();
  49. }
  50.  
  51. Arrays.sort(score);
  52.  
  53. System.out.print("Sorted order low to high is: ");
  54.  
  55. for (i = 0; i < score.length; i++)
  56. System.out.print("" + score[i] + ' ');
  57. System.out.println();
  58.  
  59. // find the max AND min integers
  60. int max = score[0];
  61. int min = score[0];
  62. for (i = 1; i < score.length; i++)
  63. {
  64. if (max < score[i]) max = score[i];
  65. if (min > score[i]) min = score[i];
  66. } // for
  67. System.out.println("The max is " + max);
  68. System.out.println("The min is " + min);
  69.  
  70. System.out.print("Average = ");
  71. System.out.println(new DecimalFormat("#.0").format(getAverage(score)));
  72.  
  73. System.out.println("" + countScoresGreater(score, 90)
  74. + " scores are A's.");
  75.  
  76. System.out.println("" + countScoresGreater(score, 80)
  77. + " scores are B's.");
  78.  
  79. System.out.println("" + countScoresGreater(score, 70)
  80. + " scores are C's.");
  81.  
  82.  
  83. } // main
  84. } // public class
Add Comment
Please, Sign In to add comment