Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Could someone tell me what's wrong with my code? I'm having trouble with Example 7 because my you will statement always comes out as a
Could someone tell me what's wrong with my code? I'm having trouble with Example 7 because my you will statement always comes out as a the congratulations statement. I'm trying to get the inputs and outputs to match. The code that is missing that was not captured in the screenshots is not relevant to the question I'm mostly have trouble with my first 2 if statements
25+ import java.util.Scanner; //Import Scanner class. 27 28 public class GradeCalculator { 29 30 public static char desiredGrade; 31 // Grading aspects 32 public static double exam1Score; 33 public static double examiWeight; 34 public static double exam1SW; // Exam 1 score times weight 35 public static double exam2Score; 36 public static double exam2Weight; 37 public static double exam2SW; // Exam 1 score times weight 38 public static double finalExamScore; 39 public static double finalExamWeight; 40 public static double finalExamSW; // Final exam score times weight 41 public static double Labs Score; 42 public static double LabsWeight; 43 public static double LabsSW; // Labs score times weight 44 public static double projectsScore; 45 public static double projectsWeight; 46 public static double projectsSW; // Projects score times weight 47 public static double participationScore; 48 public static double participationWeight; 49 public static double participationsW; // Participation score times weight 50 public static double quizzesScore; 51 public static double quizzesWeight; 52 public static double quizzessW; // Quizzes score times weight 53 // Calculations 54 public static double totalKnown GradesW; // Total known grade score times weight 55 public static double totalKnownGradeWeight; 56 public static double currentScore; 57 public static double avgToFinalLetterGrade; 58 public static double finaloverall Score; public static char currentLetterGrade; public static void main(String[] args) { // Grading Scale System.out.println("Grading Scale:"); System.out.println("Alt90 - 100"); System.out.println("B\t80 - 89"); System.out.println("C\t70 - 79"); System.out.println("D\t60 - 69"); System.out.println("F\tbelow 60"); Line: // Scanner Scanner keyboard = new Scanner(System.in); 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 // User input on what grade they want System.out.print("What letter grade do you want to achieve for the course?"); char desiredGrade = keyboard.next().charAt(0); // Error message for final grade desiredGrade = Character.toUpperCase(desiredGrade); if (!(desiredGrade == 'A' || desiredGrade == 'B' || desiredGrade == 'C' || desiredGrade == 'D' || desiredGrade == 'F')) { System.out.println("The input is invalid."); System.exit(); } // Weight percentages System.out.println("Enter percentage weights below."); System.out.print("Exam 1:\t\t "); double examiWeight = keyboard.nextDouble(); System.out.print("Exam 2:\t\t "); double exam2Weight = keyboard.nextDouble(); System.out.print("Final Exam:\t "); 92 93 94 95 96 97 98 99 1100 101 102 103 104 105 106 107 double finalExamWeight = keyboard.nextDouble(); System.out.print("Labs:\t\t "); double labsWeight = keyboard.nextDouble(); System.out.print("Projects:\t "); double projectsWeight = keyboard.nextDouble(); System.out.print("Participation:\t "); double participationWeight = keyboard.nextDouble(); System.out.print("Quizzes: \t"); double quizzesWeight = keyboard.nextDouble(); // Weight percentages error message double totalWeight = examiWeight + exam2Weight + finalExamweight + labsWeight + projectsWeight + participationWeight + quizzesWeight; if (totalWeight 100) { System.out.println("Weights don't add up to 100, program exiting..."); System.exit(); } 108 109 110 1111 112 113 114 115 116 117 118 1119 //User inputed scores String userAnswer; // User Input: Y or NI System.out.print("Do you know your exam 1 score?"); userAnswer = keyboard.next(); if (userAnswer.equalsIgnoreCase("YES") || userAnswer.equals IgnoreCase("Y")) { System.out.print("Score received on exam 1:"); exam1Score = keyboard.nextDouble(); exam1SW = exam1Score * examiWeight; totalKnown GradeSW += exam1SW; totalKnownGradeWeight += examiWeight; // Exam 2 Score System.out.print("Do you know your exam 2 score?"); 120 1121 122 1123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 userAnswer = keyboard.next(); if (userAnswer.equals IgnoreCase("YES") || userAnswer.equalsIgnoreCase("Y")) { System.out.print("Score received on exam 2:"); exam2Score = keyboard.nextDouble(); exam2SW = exam2Score * exam2Weight; totalKnown GradeSW += exam2SW; totalKnown GradeWeight += exam2Weight; // Final Exam Score System.out.print("Do you know your final exam score?"); userAnswer = keyboard.next(); if (userAnswer.equalsIgnoreCase("YES") || userAnswer.equals IgnoreCase("Y")) { System.out.print("Score received on final exam:"); finalExamScore = keyboard.nextDouble(); finalExamSW = finalExamScore * finalExamWeight; totalKnown GradeSW += final ExamSW; totalKnownGradeWeight += finalExamweight; } } } // Labs Score System.out.print("Do you know your lab average?"); userAnswer = keyboard.next(); if (userAnswer.equalsIgnoreCase("YES") || userAnswer.equals IgnoreCase("Y")) { System.out.print("Average lab grade: "); LabsScore = keyboard.nextDouble(); Labs SW = Labs Score labsWeight; totalKnown GradeSW += LabssW; totalKnownGradeWeight += labsWeight; } // Projects Score System.out.print("Do you know your project average?"); userAnswer = keyboard.next(); if (userAnswer.equalsIgnoreCase("YES") || userAnswer.equalsIgnoreCase("Y")) { 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 System.out.print("Average project grade:"); projectsScore = keyboard.nextDouble(); projectsSW = projectsScore * projectsWeight; totalKnown GradeSW += projectsSW; totalKnown GradeWeight += projectsWeight; } // Participation Score System.out.print("Do you know your participation average?"); userAnswer = keyboard.next(); if (userAnswer.equals IgnoreCase("YES") || userAnswer.equals IgnoreCase("Y")) { System.out.print("Average participation grade:"); participationScore = keyboard.nextDouble(); participationsW = participationScore * participationWeight; totalKnownGradeSW += participationsW; totalKnownGradeWeight += participationWeight; } // Quizzes Score System.out.print("Do you know your quiz average?"); userAnswer = keyboard.next(); if (userAnswer.equals IgnoreCase("YES") || userAnswer.equalsIgnoreCase("Y")) { System.out.print("Average quiz grade:"); quizzesScore = keyboard.nextDouble(); quizzessW = quizzesScore * quizzesWeight; totalknownGradeSW += quizzessw; totalKnownGradeWeight += quizzesWeight; } // currentScore Calculation currentScore = totalKnownGradesW/totalKnownGradeWeight; // finaloverallScore Calculation if (desiredGrade == 'A') { finalOverallscore = 90; 191 192 1193 194 195 196 197 198 199 200 201 } else if (desiredGrade == 'B') { finalOverall Score = 80; } else if (desiredGrade == 'C') { finalOverallScore = 70; } else if (desiredGrade == 'D') { finaLoverallScore = 60; } else { finalOverallscore = 0; } 1202 // Average to final letter grade calculation if (totalKnown GradeWeight == 100) { avgToFinalLetterGrade = (100 * finaloverallScore - totalKnown GradeSW); } else { avgToFinalLetterGrade = (100 * finalOverallScore - totalKnownGradeSW)/(100 - totalKnownGradewei } avgToFinalLetterGrade = Math.round(avgToFinalLetterGrade * 100.0) / 100.0; 203 204 1205 1206 207 1208 209 210 211 1212 1213 1214 215 216 1217 1218 1219 220 221 222 223 1224 // Current letter grade if (currentScore >= 90) { currentLetterGrade = 'A'; } else if (currentScore >= 80) { currentLetterGrade = 'B'; } else if (currentScore >= 70) { currentLetterGrade = 'C'; } else if (current Score >= 6A) { Line: 215 'A; current LetterGrade = } else if (currentScore >= 80) { currentLetterGrade = 'B'; } else if (currentScore >= 70) { currentLetterGrade = 'C'; } else if (currentScore >= 60) { currentLetterGrade = 'D'; } else { currentLetterGrade = 'F'; } 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 } // Print Statements System.out.printf("Current Grade Score: %.2f ", currentScore); System.out.println("Your current letter grade: " + currentLetterGrade); if (avgToFinalLetterGrade 0) { System.out.println("You will recieve at least a grade of" + desiredGrade); } else if (avgToFinalLetterGrade > 100) { System.out.println("Unfortunately, a grade of " + desiredGrade + " is not possible."); } else { System.out.println("In order to receive a grade of " + desiredGrade +", " + ' ' + "you need to } keyboard.close(); } A 90 - 100 B 80 - 89 70 - 79 D 60 - 69 F below 60 What letter grade do you want to achieve for the course?D Enter percentage weights below. Exam 1: 20 Exam 2: 20 Final Exam: 20 Labs: 10 Projects: 10 Participation: 10 Quizzes: 10 Do you know your exam 1 score?y Score received on exam 1:100 Do you know your exam 2 score?y Score received on exam 2:100 Do you know your final exam score?Y Score received on final exam: 100 Do you know your lab average?y Average lab grade: 100 Do you know your project average? Average project grade: 100 Do you know your participation average?n Do you know your quiz average?N Current grade score: 100.00 Your current letter grade: A You will receive at least a grade of D. Example 8: user knows all scores and does not obtain desired grade Grading Scale: A 90 - 100 B 80 - 89 70 - 79 D 60 - 69 F below 60 What letter grade do you want to achieve for the course?A Enter percentage weights below. Exam 1: 15 Exam 2: 20 Final Exam: 20 Labs: 15 Projects: 20 Participation: 3 Quizzes: 7 Do you know your exam 1 score?yes Score received on exam 1:79 Do you know your exam 2 score?yes Score received on exam 2:72 Do you know your final exam score?y Score received on final exam: 91 Do you know your lab average?y Average lab grade:92 25+ import java.util.Scanner; //Import Scanner class. 27 28 public class GradeCalculator { 29 30 public static char desiredGrade; 31 // Grading aspects 32 public static double exam1Score; 33 public static double examiWeight; 34 public static double exam1SW; // Exam 1 score times weight 35 public static double exam2Score; 36 public static double exam2Weight; 37 public static double exam2SW; // Exam 1 score times weight 38 public static double finalExamScore; 39 public static double finalExamWeight; 40 public static double finalExamSW; // Final exam score times weight 41 public static double Labs Score; 42 public static double LabsWeight; 43 public static double LabsSW; // Labs score times weight 44 public static double projectsScore; 45 public static double projectsWeight; 46 public static double projectsSW; // Projects score times weight 47 public static double participationScore; 48 public static double participationWeight; 49 public static double participationsW; // Participation score times weight 50 public static double quizzesScore; 51 public static double quizzesWeight; 52 public static double quizzessW; // Quizzes score times weight 53 // Calculations 54 public static double totalKnown GradesW; // Total known grade score times weight 55 public static double totalKnownGradeWeight; 56 public static double currentScore; 57 public static double avgToFinalLetterGrade; 58 public static double finaloverall Score; public static char currentLetterGrade; public static void main(String[] args) { // Grading Scale System.out.println("Grading Scale:"); System.out.println("Alt90 - 100"); System.out.println("B\t80 - 89"); System.out.println("C\t70 - 79"); System.out.println("D\t60 - 69"); System.out.println("F\tbelow 60"); Line: // Scanner Scanner keyboard = new Scanner(System.in); 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 // User input on what grade they want System.out.print("What letter grade do you want to achieve for the course?"); char desiredGrade = keyboard.next().charAt(0); // Error message for final grade desiredGrade = Character.toUpperCase(desiredGrade); if (!(desiredGrade == 'A' || desiredGrade == 'B' || desiredGrade == 'C' || desiredGrade == 'D' || desiredGrade == 'F')) { System.out.println("The input is invalid."); System.exit(); } // Weight percentages System.out.println("Enter percentage weights below."); System.out.print("Exam 1:\t\t "); double examiWeight = keyboard.nextDouble(); System.out.print("Exam 2:\t\t "); double exam2Weight = keyboard.nextDouble(); System.out.print("Final Exam:\t "); 92 93 94 95 96 97 98 99 1100 101 102 103 104 105 106 107 double finalExamWeight = keyboard.nextDouble(); System.out.print("Labs:\t\t "); double labsWeight = keyboard.nextDouble(); System.out.print("Projects:\t "); double projectsWeight = keyboard.nextDouble(); System.out.print("Participation:\t "); double participationWeight = keyboard.nextDouble(); System.out.print("Quizzes: \t"); double quizzesWeight = keyboard.nextDouble(); // Weight percentages error message double totalWeight = examiWeight + exam2Weight + finalExamweight + labsWeight + projectsWeight + participationWeight + quizzesWeight; if (totalWeight 100) { System.out.println("Weights don't add up to 100, program exiting..."); System.exit(); } 108 109 110 1111 112 113 114 115 116 117 118 1119 //User inputed scores String userAnswer; // User Input: Y or NI System.out.print("Do you know your exam 1 score?"); userAnswer = keyboard.next(); if (userAnswer.equalsIgnoreCase("YES") || userAnswer.equals IgnoreCase("Y")) { System.out.print("Score received on exam 1:"); exam1Score = keyboard.nextDouble(); exam1SW = exam1Score * examiWeight; totalKnown GradeSW += exam1SW; totalKnownGradeWeight += examiWeight; // Exam 2 Score System.out.print("Do you know your exam 2 score?"); 120 1121 122 1123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 userAnswer = keyboard.next(); if (userAnswer.equals IgnoreCase("YES") || userAnswer.equalsIgnoreCase("Y")) { System.out.print("Score received on exam 2:"); exam2Score = keyboard.nextDouble(); exam2SW = exam2Score * exam2Weight; totalKnown GradeSW += exam2SW; totalKnown GradeWeight += exam2Weight; // Final Exam Score System.out.print("Do you know your final exam score?"); userAnswer = keyboard.next(); if (userAnswer.equalsIgnoreCase("YES") || userAnswer.equals IgnoreCase("Y")) { System.out.print("Score received on final exam:"); finalExamScore = keyboard.nextDouble(); finalExamSW = finalExamScore * finalExamWeight; totalKnown GradeSW += final ExamSW; totalKnownGradeWeight += finalExamweight; } } } // Labs Score System.out.print("Do you know your lab average?"); userAnswer = keyboard.next(); if (userAnswer.equalsIgnoreCase("YES") || userAnswer.equals IgnoreCase("Y")) { System.out.print("Average lab grade: "); LabsScore = keyboard.nextDouble(); Labs SW = Labs Score labsWeight; totalKnown GradeSW += LabssW; totalKnownGradeWeight += labsWeight; } // Projects Score System.out.print("Do you know your project average?"); userAnswer = keyboard.next(); if (userAnswer.equalsIgnoreCase("YES") || userAnswer.equalsIgnoreCase("Y")) { 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 System.out.print("Average project grade:"); projectsScore = keyboard.nextDouble(); projectsSW = projectsScore * projectsWeight; totalKnown GradeSW += projectsSW; totalKnown GradeWeight += projectsWeight; } // Participation Score System.out.print("Do you know your participation average?"); userAnswer = keyboard.next(); if (userAnswer.equals IgnoreCase("YES") || userAnswer.equals IgnoreCase("Y")) { System.out.print("Average participation grade:"); participationScore = keyboard.nextDouble(); participationsW = participationScore * participationWeight; totalKnownGradeSW += participationsW; totalKnownGradeWeight += participationWeight; } // Quizzes Score System.out.print("Do you know your quiz average?"); userAnswer = keyboard.next(); if (userAnswer.equals IgnoreCase("YES") || userAnswer.equalsIgnoreCase("Y")) { System.out.print("Average quiz grade:"); quizzesScore = keyboard.nextDouble(); quizzessW = quizzesScore * quizzesWeight; totalknownGradeSW += quizzessw; totalKnownGradeWeight += quizzesWeight; } // currentScore Calculation currentScore = totalKnownGradesW/totalKnownGradeWeight; // finaloverallScore Calculation if (desiredGrade == 'A') { finalOverallscore = 90; 191 192 1193 194 195 196 197 198 199 200 201 } else if (desiredGrade == 'B') { finalOverall Score = 80; } else if (desiredGrade == 'C') { finalOverallScore = 70; } else if (desiredGrade == 'D') { finaLoverallScore = 60; } else { finalOverallscore = 0; } 1202 // Average to final letter grade calculation if (totalKnown GradeWeight == 100) { avgToFinalLetterGrade = (100 * finaloverallScore - totalKnown GradeSW); } else { avgToFinalLetterGrade = (100 * finalOverallScore - totalKnownGradeSW)/(100 - totalKnownGradewei } avgToFinalLetterGrade = Math.round(avgToFinalLetterGrade * 100.0) / 100.0; 203 204 1205 1206 207 1208 209 210 211 1212 1213 1214 215 216 1217 1218 1219 220 221 222 223 1224 // Current letter grade if (currentScore >= 90) { currentLetterGrade = 'A'; } else if (currentScore >= 80) { currentLetterGrade = 'B'; } else if (currentScore >= 70) { currentLetterGrade = 'C'; } else if (current Score >= 6A) { Line: 215 'A; current LetterGrade = } else if (currentScore >= 80) { currentLetterGrade = 'B'; } else if (currentScore >= 70) { currentLetterGrade = 'C'; } else if (currentScore >= 60) { currentLetterGrade = 'D'; } else { currentLetterGrade = 'F'; } 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 } // Print Statements System.out.printf("Current Grade Score: %.2f ", currentScore); System.out.println("Your current letter grade: " + currentLetterGrade); if (avgToFinalLetterGrade 0) { System.out.println("You will recieve at least a grade of" + desiredGrade); } else if (avgToFinalLetterGrade > 100) { System.out.println("Unfortunately, a grade of " + desiredGrade + " is not possible."); } else { System.out.println("In order to receive a grade of " + desiredGrade +", " + ' ' + "you need to } keyboard.close(); } A 90 - 100 B 80 - 89 70 - 79 D 60 - 69 F below 60 What letter grade do you want to achieve for the course?D Enter percentage weights below. Exam 1: 20 Exam 2: 20 Final Exam: 20 Labs: 10 Projects: 10 Participation: 10 Quizzes: 10 Do you know your exam 1 score?y Score received on exam 1:100 Do you know your exam 2 score?y Score received on exam 2:100 Do you know your final exam score?Y Score received on final exam: 100 Do you know your lab average?y Average lab grade: 100 Do you know your project average? Average project grade: 100 Do you know your participation average?n Do you know your quiz average?N Current grade score: 100.00 Your current letter grade: A You will receive at least a grade of D. Example 8: user knows all scores and does not obtain desired grade Grading Scale: A 90 - 100 B 80 - 89 70 - 79 D 60 - 69 F below 60 What letter grade do you want to achieve for the course?A Enter percentage weights below. Exam 1: 15 Exam 2: 20 Final Exam: 20 Labs: 15 Projects: 20 Participation: 3 Quizzes: 7 Do you know your exam 1 score?yes Score received on exam 1:79 Do you know your exam 2 score?yes Score received on exam 2:72 Do you know your final exam score?y Score received on final exam: 91 Do you know your lab average?y Average lab grade:92Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started