Rawri
2013-07-26 21:10:55 UTC
Here is homework prompt:
Write a program that asks the user to enter 5 test scores. Your program should then display a letter grade for each test score, the average test score and the overall letter grade for the average score. You can NOT use a for loop or an array (we haven’t even covered that) in this program – the point is to learn how to define methods and call them several times if necessary.
Your program is required to have and use the following methods: (These methods CAN NOT be void methods)
• calcAverage – This method must accept 5 test scores as arguments and must return the average of the 5 scores (NOT A VOID METHOD).
• determineGrade – This method must accept a test score as an argument and must return a letter grade for the score it accepted as an argument (NOT A VOID METHOD).
Here’s the grading scale:
Score Letter Grade
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F
Here is what I have:
import java.util.Scanner;
public class TestGrade
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int testA;
int testB;
int testC;
int testD;
int testF;
double calcAverage;
double determineGrade;
System.out.println("Please enter the first score between 0 and 100: ");
determineGrade1 = keyboard.nextInt();
System.out.println("Please enter the second score between 0 and 100: ");
determineGrade2 = keyboard.nextInt();
System.out.println("Please enter the third score between 0 and 100: ");
determineGrade3 = keyboard.nextInt();
System.out.println("Please enter the fourth score between 0 and 100: ");
determineGrade4 = keyboard.nextInt();
System.out.println("Please enter the fifth score between 0 and 100: ");
determineGrade5 = keyboard.nextInt();
keyboard.nextLine();
double average = calcAverage(testA, testB, testC, testD, testF);
System.out.println("The Average grade is ");
determineGrade(average);
}
public static double calAverage(int testA, int testB, int testC, int testD, int testF);
{
double average = (testA + testB + testC + testD + testF) /5;
return average;
}
public static double determineGrade(double average)
{
if (average>90);
{
System.out.println("You recieved an A");
}
else if (double average>=80);
{
System.out.println("You recieved a B");
}
else if (average>=70);
{
System.out.println("You recieved a C");
}
else if (average>=60);
{
System.out.println("You recieved a D");
}
else if (average<60);
{
System.out.println("You recieved an F");
}
return 0;
System.out.println("The first letter grade is: F");
System.out.println("The second letter grade is: D");
System.out.println("The third letter grade is: C");
Sysytem.out.println("The fourth letter grade is: B");
System.out.println("The fifth letter grade is: A");
System.out.println("\n");
System.out.println("The average test score is:");
System.out.println("The average grade is:");
}
}