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

Help with printf on java requested. --------------------------------------------

ID: 3752707 • Letter: H

Question

Help with printf on java requested.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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);

Explanation / Answer

Instead of using : System.out.printf("Current Grade Score:%1.2f " + CurrentScore);

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

That is replace '+' with ','

Because using printf you need to specify the value to replace the placeholder with instead of using string concatenation.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote