Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. Scanner reader = new Scanner(System.in);
  2. System.out.println("Welcome to the Exam Histogram program by Henry Yates.");
  3. System.out.println("Please enter 0-100 for the marks and enter -1 to complete data entry");
  4. int total = 0, count = 0;
  5. double average = 0.0;
  6. int marks = 0;
  7. int BotMarks = 0;
  8. int LowMarks = 0;
  9. int MedMarks = 0;
  10. int HighMarks = 0;
  11. int Highest = 0;
  12. int Lowest = 1000;
  13. int MarksEntered = 0;
  14. while (marks != -1) {
  15. try {
  16. marks = reader.nextInt();
  17. } catch (InputMismatchException e) {
  18. marks = 1000;
  19. continue;
  20. }
  21. while (marks < -1 || marks > 100) {
  22. if (marks == -1) {
  23. total++;
  24. count=count-1;
  25. } else {
  26. System.out.println("Invalid input please enter 0-100");
  27. marks = reader.nextInt();
  28. }
  29.  
  30. }
  31. total = total + marks;
  32. count++;
  33. //total++;
  34.  
  35.  
  36. if (marks > Highest) {
  37. Highest = marks;
  38. }
  39. if (marks < Lowest && marks >= 0) {
  40. Lowest = marks;
  41. }
  42. if (marks != -1) {
  43. MarksEntered++;
  44. }
  45. if (marks <= 100 && marks >= 70) {
  46. HighMarks++;
  47. } else if (marks <= 69 && marks >= 40) {
  48. MedMarks++;
  49. } else if (marks <= 39 && marks >= 30) {
  50. LowMarks++;
  51. } else if (marks >= 29 || marks == 0 || marks >= 1) {
  52. BotMarks++;
  53. }
  54.  
  55. } // end of main while loop
  56. System.out.print("70-100: ");
  57. for (int a = 0; a < HighMarks; a++) {
  58. System.out.print("*");
  59. }
  60. System.out.println("");
  61. System.out.print("40-69 : ");
  62. for (int a = 0; a < MedMarks; a++) {
  63. System.out.print("*");
  64. }
  65. System.out.println("");
  66. System.out.print("30-39 : ");
  67. for (int a = 0; a < LowMarks; a++) {
  68. System.out.print("*");
  69. }
  70. System.out.println(" ");
  71. System.out.print("0-29 : ");
  72. for (int a = 0; a < BotMarks; a++) {
  73. System.out.print("*");
  74. }
  75. System.out.println("");
  76. int StudentsPass = 0;
  77. count=count-1;
  78. total++;
  79. average = (total / count);
  80. StudentsPass = MedMarks + HighMarks;
  81. System.out.println("The amount of students who passed are " + StudentsPass);
  82. System.out.println("The Lowest Mark is: " + Lowest);
  83. System.out.println("The Highest Mark is: " + Highest);
  84. System.out.println("The Average Mark is: " + average);
  85.  
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement