Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I get this java.util.MissingFormatArgumentException error. I\'m not sure how to

ID: 3752691 • Letter: I

Question

I get this java.util.MissingFormatArgumentException error. I'm not sure how to round the value if print f doesn't work in this way.

SumofWeights2 = (Exam1Weight + Exam2Weight + FinalExamWeight + LabsWeight + ProjectsWeight + AttendanceWeight + QuizzesWeight);  
   SumofWeightxScore = (Exam1Weight*Exam1Score + Exam2Weight*Exam2Score + FinalExamScore*FinalExamWeight + LabAvg*LabsWeight + ProjectAvg*ProjectsWeight + QuizAvg*QuizzesWeight + AttendanceAvg*AttendanceWeight);
       CurrentScore = (SumofWeightxScore/SumofWeights2);
       x = (HundredxFinalOverallScore - SumofWeightxScore);
       y = (100 - SumofWeights2);
       AvgToFinalLetterGrade = (x/y);
       System.out.printf("Current Grade Score:%1.2f " + CurrentScore);
       System.out.println();

ERROR CODE BELOW:

Current Grade Score:Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '%1.2f'
   at java.util.Formatter.format(Unknown Source)
   at java.io.PrintStream.format(Unknown Source)
   at java.io.PrintStream.printf(Unknown Source)
   at GradeCalculator.main(GradeCalculator.java:251) this is line: System.out.printf("Current Grade Score:%1.2f " + CurrentScore);

ar- yawr .uul. '.inLin() ; De, yas know your Lab Awerap? y Ua yuu know your Prujuct Awugu?y Ua yu kow your Qui: Arug Lab arud: 5 O lype here to search

Explanation / Answer

Please correct this: "  System.out.printf("Current Grade Score:%1.2f " + CurrentScore); "

in to

" System.out.printf("Current Grade Score:%1.2f " , CurrentScore); "

Instead of '+' use ',' beacause if you are using printf you need to specify the placeholders as printf parameters.

That is instead of using string concatenation, specify the value to replace the placeholder.

Please upvote if you like the answer and comment if you need any further information in this regard.