Kotlinlearncs.online LogoJava
Return to List

Homework: Letter Grade Printout

Created By: Michal Lampejo
/ Version: 2023.7.0

Let's write a method to print a set of letter grades based on numeric scores. Create a method named printLetterGrades that accepts a non-null array of double values. If the array is empty, don't print anything.

Otherwise, for each value in the array, print a line to the console in the following format:

Student 1,B,3.3

The first value is in the format "Student N", where N is the index in the array but starting at 1. So the first student is "Student 1", the second "Student 2", and so on. (0-based indexing tends to confuse people who aren't computer scientists.)

The second value is the student's letter grade based on the following scale:

  • >= 4.0: A
  • >= 3.0 && < 4.0: B
  • >= 2.0 && < 3.0: C
  • >= 1.0 && < 2.0: D
  • otherwise, F

You can assume that values in the array will be between 0.0 and 5.0, inclusive.

The third value is the student's raw score.

You should also print "--- GRADES START ---" at the beginning and "--- GRADES END ---" at the end, each on their own line, but only if the array is not empty.

Related Lessons

Stuck? You may find these lessons helpful: