Advertisement
Guest User

groupWork

a guest
Jun 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Program {
  4.  
  5. public static void main(String[] args)
  6. {
  7.  
  8. /*
  9. * Nick Taylor
  10. * Philip Lempke
  11. * Mariano Gonzalez
  12. * Not Neal 'no-show' McMahon
  13. *
  14. * Our program prompts the user to enter a list of grades so that they can calculate_
  15. * the sum of grades, the averages of each grade, min/max grade, and possible extra credit_
  16. * It will then print you off a summary of this information_
  17. * In doing this we learned how to create multiple comments with "/*" instead of "//"
  18. * how to use an "if" statement in a println in order to add an additional option to the statement
  19. * how to take an arbitrary amount of numbers/inputs from a user and calculate results from them
  20. * how to use a screen sharing application other than adobe connect so that we can work together_
  21. * remotely from our respective homes
  22. *
  23. *
  24. * Variables
  25. * Initialize
  26. * Request input
  27. * Divide the input by grade, counters and sums go up
  28. * determine if input is lower/greater than min/max and change min/max accordingly
  29. * calculate averages of individual grades and total
  30. * calculate sums of individual grades and total
  31. * Output
  32. */
  33.  
  34. // TODO Auto-generated method stub
  35. Scanner keyboard = new Scanner(System.in);
  36.  
  37. //Declare the variables
  38. int gradeA, gradeB, gradeC, gradeD, gradeF;
  39. double sumA, sumB, sumC, sumD, sumF;
  40. double minGrade = 1000;
  41. double maxGrade = 0;
  42. double sum;
  43. double averageGrade;
  44. int counter;
  45. int extraCreditCounter;
  46.  
  47. //initialize the variables
  48. sum = 0;
  49. counter = 0;
  50. gradeA = 0;
  51. gradeB = 0;
  52. gradeC = 0;
  53. gradeD = 0;
  54. gradeF = 0;
  55. sumA = 0;
  56. sumB = 0;
  57. sumC = 0;
  58. sumD = 0;
  59. sumF = 0;
  60. extraCreditCounter = 0;
  61.  
  62. //prompt the user for the grades they'd like to input
  63. System.out.println("Please enter the list of scores from 0 to 100: ");
  64. System.out.println("Please enter a negative number to stop entering grades");
  65. int gradeInputed = keyboard.nextInt();
  66.  
  67. // establish conditions for each respective grade as well as adding up
  68. // the sums of each grade
  69. while (gradeInputed >=0)
  70. {
  71. counter++;
  72. sum += gradeInputed;
  73. if (gradeInputed >= 90)
  74. {
  75. gradeA++;
  76. sumA += gradeInputed;
  77. if (gradeInputed > 100)
  78. {
  79. extraCreditCounter++;
  80. }
  81. }
  82. else if(gradeInputed >= 80 && gradeInputed <=89)
  83. {
  84. gradeB++;
  85. sumB += gradeInputed;
  86. }
  87. else if(gradeInputed >= 70 && gradeInputed <=79)
  88. {
  89. gradeC++;
  90. sumC += gradeInputed;
  91. }
  92. else if(gradeInputed >= 60 && gradeInputed <=69)
  93. {
  94. gradeD++;
  95. sumD += gradeInputed;
  96. }
  97. else if(gradeInputed >= 0 && gradeInputed <=59)
  98. {
  99. gradeF++;
  100. sumF += gradeInputed;
  101. }
  102. else if(gradeInputed < 0)
  103. System.out.println("You have entered an invalid grade. Please try again.");
  104.  
  105. if (gradeInputed > maxGrade)
  106. {
  107. maxGrade = gradeInputed;
  108. }
  109. if (gradeInputed < minGrade)
  110. {
  111. minGrade = gradeInputed;
  112. }
  113. gradeInputed = keyboard.nextInt();
  114.  
  115. }
  116. // create a condition for the average grade
  117. averageGrade = sum / counter;
  118. if (sumA >0)
  119. {
  120. sumA = sumA / gradeA;
  121. }
  122. if (sumB >0)
  123. {
  124. sumB = sumB / gradeB;
  125. }
  126. if (sumC >0)
  127. {
  128. sumC = sumC / gradeC;
  129. }
  130. if (sumD >0)
  131. {
  132. sumD = sumD / gradeD;
  133. }
  134. if (sumF >0)
  135. {
  136. sumF = sumF / gradeF;
  137. }
  138.  
  139.  
  140. // Print out the report for all of the grades the user entered
  141. System.out.println("The sum of scores is: " +sum);
  142. System.out.println();
  143.  
  144. System.out.println("The total number of scores: " + counter);
  145. System.out.print("The total number of A's: " + gradeA);
  146. if (extraCreditCounter > 0)
  147. {
  148. System.out.println(" with " + extraCreditCounter + " receiving extra credit!");
  149. }
  150. else
  151. {
  152. System.out.println();
  153. }
  154. System.out.println("The total number of B's: " + gradeB);
  155. System.out.println("The total number of C's: " + gradeC);
  156. System.out.println("The total number of D's: " + gradeD);
  157. System.out.println("The total number of F's: " + gradeF);
  158. System.out.println();
  159.  
  160. System.out.println("The average grade is: " + averageGrade);
  161. System.out.println("The average A is: " + sumA);
  162. System.out.println("The average B is: " + sumB);
  163. System.out.println("The average C is: " + sumC);
  164. System.out.println("The average D is: " + sumD);
  165. System.out.println("The average F is: " + sumF);
  166. System.out.println();
  167.  
  168. System.out.println("The highest grade is: " + maxGrade);
  169. System.out.println("The lowest grade is: " + minGrade);
  170. }
  171.  
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement