Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GradeCalculator {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. //declaring the variables WEIGHT
  8. int exam1Weight, exam2Weight;
  9. int finalExamWeight, labWeight;
  10. int projectWeight, attendanceWeight, quizWeight;
  11. //initialize
  12. exam1Weight = 0;
  13. exam2Weight = 0;
  14. finalExamWeight = 0;
  15. labWeight = 0;
  16. projectWeight = 0;
  17. attendanceWeight = 0;
  18. quizWeight = 0;
  19.  
  20. //declaring the variable SCORE
  21. int exam1Score, exam2Score, finalExamScore;
  22. int labScore, projectScore, attendanceScore, quizScore;
  23. //initialize
  24. exam1Score = 0;
  25. exam2Score = 0;
  26. finalExamScore = 0;
  27. labScore = 0;
  28. projectScore = 0;
  29. attendanceScore = 0;
  30. quizScore = 0;
  31.  
  32. //scanner for inputs
  33. Scanner keyboard = new Scanner(System.in);
  34.  
  35. //printing LETTERGRADE and POINTRANGE
  36. System.out.println("Grading Scale:\n" +
  37. "A\t\t 90 - 100\n" +
  38. "B\t\t 80 - 89\n" +
  39. "C\t\t 70 - 79\n" +
  40. "D\t\t 60 - 69\n" +
  41. "F\t\t below 60");
  42.  
  43. //declaring variables
  44. int finalOverallScore, totalKnownGradeWeight;
  45. double currentScore, avgToFinalLetterGrade;
  46. String input, letterGrade;
  47.  
  48. System.out.print("What letter grade do you want to achieve for the course? ");
  49.  
  50. String desiredGrade = keyboard.nextLine();
  51. //starting the if else statements
  52. if (desiredGrade.equals("A")) {
  53. finalOverallScore = 90;}
  54.  
  55. else if (desiredGrade.equals("B")) {
  56. finalOverallScore = 80;}
  57.  
  58. else if (desiredGrade.equals("C")) {
  59. finalOverallScore = 70;}
  60.  
  61. else if(desiredGrade.equals("D")) {
  62. finalOverallScore = 50;}
  63.  
  64. else if(desiredGrade.equals("F")) {
  65. finalOverallScore = 50;}
  66. else {
  67. System.out.println("Input Error");
  68. System.exit(0);
  69. }
  70.  
  71. //entering the scores
  72. totalKnownGradeWeight = 0;
  73. //asking user to enter percentage weights
  74. System.out.print("Enter Percent Weights:\nExam 1:\t\t");
  75.  
  76. exam1Weight = keyboard.nextInt();
  77.  
  78. System.out.print("Exam 2:\t\t");
  79. exam2Weight = keyboard.nextInt();
  80.  
  81. System.out.print("Final Exam:\t");
  82. finalExamWeight = keyboard.nextInt();
  83.  
  84. System.out.print("Labs:\t\t");
  85. labWeight = keyboard.nextInt();
  86.  
  87. System.out.print("Projects:\t");
  88. projectWeight = keyboard.nextInt();
  89.  
  90. System.out.print("Attendance:\t");
  91. attendanceWeight = keyboard.nextInt();
  92.  
  93. System.out.print("Quizzes:\t");
  94. quizWeight = keyboard.nextInt();
  95.  
  96.  
  97. int sumOfGradeWeights = (exam1Weight + exam2Weight + finalExamWeight + labWeight + projectWeight + attendanceWeight + quizWeight);
  98.  
  99. if (sumOfGradeWeights > 100 || sumOfGradeWeights < 100) {
  100. System.out.print("Weights don’t add up to 100, program exiting...");
  101. System.exit(0);
  102. }
  103. else
  104. System.out.println("Enter your scores out of a 100:");
  105.  
  106. //prompt to enter the score
  107. System.out.print("Do you know your Exam 1 score?");
  108. String studentInput;
  109. studentInput = keyboard.next();
  110.  
  111. //if else statements for unknown exam 1 & 2 scores
  112.  
  113. if (studentInput.equalsIgnoreCase("yes") || studentInput.equalsIgnoreCase("y")) {
  114.  
  115. System.out.print("Score received on exam 1:");
  116. exam1Score = keyboard.nextInt();
  117. keyboard.next();
  118. totalKnownGradeWeight += exam1Weight;
  119.  
  120. System.out.print("Do you know your Exam 2 score?");
  121. studentInput = keyboard.nextLine();
  122. if (studentInput.equalsIgnoreCase("yes") || studentInput.equalsIgnoreCase("y"))
  123. {
  124. System.out.print("Score received on final exam: ");
  125. finalExamScore = keyboard.nextInt();
  126. keyboard.next();
  127. totalKnownGradeWeight += finalExamWeight;
  128. }
  129.  
  130. //using switch statements--
  131.  
  132. //switch statements for project
  133. System.out.print("Do you know your project average? ");
  134. input = keyboard.next();
  135. switch (input)
  136. {
  137. case "yes":
  138. case "ye":
  139. case "y":
  140. System.out.print("Average Project Grade: ");
  141. projectScore = keyboard.nextInt();
  142. totalKnownGradeWeight += projectWeight;
  143. break;
  144. default:
  145. projectScore = 0;
  146. projectWeight = 0;
  147. break;
  148. }
  149.  
  150. //switch statements for attendance
  151. System.out.print("Do you know your attendance average? ");
  152. input = keyboard.next();
  153. switch (input)
  154. {
  155. case "yes":
  156. case "ye":
  157. case "y":
  158. System.out.print("Average Attendance Grade: ");
  159. attendanceScore = keyboard.nextInt();
  160. totalKnownGradeWeight += attendanceWeight;
  161. break;
  162. default:
  163. attendanceScore = 0;
  164. attendanceWeight = 0;
  165. break;
  166. }
  167.  
  168. //switch statements for quiz
  169. System.out.print("Do you know your quiz average? ");
  170. input = keyboard.next();
  171. switch (input)
  172. {
  173. case "yes":
  174. case "ye":
  175. case "y":
  176. System.out.print("Average Quiz Grade: ");
  177. quizScore = keyboard.nextInt();
  178. totalKnownGradeWeight += quizWeight;
  179. break;
  180. default:
  181. quizScore = 0;
  182. quizWeight = 0;
  183. break;
  184. }
  185. }
  186. //computing the scores
  187. double gradeScore;
  188. gradeScore = (exam1Weight * exam1Score) + (exam2Weight * exam2Score) + (finalExamWeight * finalExamScore) + (labWeight * labScore) + (projectWeight * projectScore) + (attendanceWeight * attendanceScore) + (quizWeight * quizScore);
  189. double gradeWeight;
  190. gradeWeight = totalKnownGradeWeight;
  191. double currentScore1;
  192. currentScore1 = (gradeScore/gradeWeight);
  193.  
  194. System.out.printf("Current Score %5.2f" , currentScore1);
  195.  
  196. //Converting current score to a letter grade
  197. String currentLetterGrade;
  198. if(currentScore >= 90)
  199. {
  200. currentLetterGrade = "A";
  201. }
  202. else if(currentScore1 >= 80)
  203. {
  204. currentLetterGrade = "B";
  205. }
  206. else if(currentScore1 >= 70)
  207. {
  208. currentLetterGrade = "C";
  209. }
  210. else if(currentScore1 >= 60)
  211. {
  212. currentLetterGrade = "D";
  213. }
  214. else
  215. {
  216. currentLetterGrade = "F";
  217. }
  218. System.out.println("Your current letter grade is a " + currentLetterGrade);
  219.  
  220.  
  221. //if else statements for outputs
  222.  
  223. int gradeWanted;
  224. if(totalKnownGradeWeight == 100)
  225. {
  226. if(currentLetterGrade.equals(gradeWanted))
  227. System.out.println("Congratulations! You recieved the " + gradeWanted + " that you wanted!");
  228. else
  229. System.out.println("Sorry, you did not recieved the " + gradeWanted + " that you wanted.");
  230. System.exit(0);
  231. }
  232.  
  233. //
  234. double avgFinalLetterGradeNumerator = (100 * finalOverallScore) - gradeScore;
  235. double abgFinalLetterGradeDenominator = (100 - totalKnownGradeWeight);
  236. double avgFinalLetterGradeDenominator;
  237. avgToFinalLetterGrade = (avgFinalLetterGradeNumerator/avgFinalLetterGradeDenominator);
  238.  
  239. if(avgToFinalLetterGrade > 100)
  240. {
  241. System.out.println("Sorry, you cannot recieve a " + gradeWanted + " in the course");
  242. }
  243. else if(avgToFinalLetterGrade >= 0) {
  244. System.out.printf("You have to score an average greater than or equal to a %5.1f", avgToFinalLetterGrade);
  245. System.out.print(" in the remaining grade items to receieve a " + gradeWanted + " in the course");
  246. }
  247. else{
  248. System.out.println("You will recieve a " + gradeWanted + " no matter what");
  249. }
  250.  
  251. }
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266. }
  267.  
  268. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement