Sinisterly
Can anyone calculate average grades? - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Java, JVM, & JRE (https://sinister.li/Forum-Java-JVM-JRE)
+--- Thread: Can anyone calculate average grades? (/Thread-Can-anyone-calculate-average-grades)



Can anyone calculate average grades? - TheBlindHatter - 01-27-2014

Can anyone write something up that is as efficient as possible and that follows these instructions exactly (method names must stay the same)

Test Average and Grade

Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score.

Write the following methods in the program:

calcAverage – This method should accept five test scores as arguments and return the average of the scores.
determineGrade – This method should accept a test score as an argument and return a letter grade for the score, based on the following grading scale:


90-100 A

80-89 B

70-79 C

60-69 D

Below 60 F

//Best of luck!


RE: Can anyone calculate average grades? - blackeagle - 02-05-2014

Code:
package calculategrades; import java.util.Scanner; public class Calculategrades { public static double calcAverage(double x, double y, double z, double a, double b) { double avg = (x + y + z + a + b) / 5; return avg; } public static char determineGrade(double test) { char grade = 0; if ((test >= 90) && (test <= 100)) { grade = 'A'; } if ((test >= 80) && (test <= 89)) { grade = 'B'; } if ((test >= 70) && (test <= 79)) { grade = 'C'; } if ((test >= 60) && (test <= 69)) { grade = 'D'; } if (test < 60) { grade = 'F'; } return grade; } public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("insert 5 test scores:"); double c = in.nextDouble(); double d = in.nextDouble(); double e = in.nextDouble(); double f = in.nextDouble(); double g = in.nextDouble(); System.out.println("the average is : " + calcAverage(c, d, e, f, g)); System.out.println("insert test note to determine the grade letter"); double h = in.nextDouble(); System.out.println("grade " + determineGrade(h)); } }