ITEC 120 LAB 8 Back to Lab index page

Grade averager, new and improved.

You might want to start with the program you wrote for lab 5. Write a program that will ask the user for a type of assignment, then read grades from the user until the user enters -1. The program then averages all the scores together, displays the score to one decimal place, and assigns a letter grade to the score. The program will round the score, in other words, an 89.7 is an A.

Sample run:

Program outputs: Please enter the type of the assignment
User inputs: quiz
Program outputs: Enter score for quiz number 1. (-1 to quit):
User inputs: 90
Program outputs: Enter score for quiz number 2. (-1 to quit):
User inputs: 90
Program outputs: Enter score for quiz number 3. (-1 to quit):
User inputs: 89
Program outputs: Enter score for quiz number 4. (-1 to quit):
User inputs: -1
Program outputs:

The average of your 3 quiz grades is 89.7 A

You'll need to use some if statements (or a switch) and a loop for this lab. You might also find the Math.round method handy. Math.round is part of the java.lang package, so does not need to be imported, and it is specified like this:

static long Math.round(double num)

This means that Math.round takes one parameter, which needs to be a floating point number, and it returns a long, which is num rounded to the nearest integer. Because the method is static, you do not have to create a Math object in order to use it, you can call the method using the class name. (Keyboard methods are also static. We don't create a Keyboard object in order to call Keyboard methods. We just use the class name in front of the dot.   For example:   int input = Keyboard.readInt();   )