0

I am a beginning programmer and we were assigned to implement methods into a code. I had this grade average code working fine, but once I broke it up into methods, I could not get the return functions to work. I have tried moving brackets and rearranging the code but to no avail. I believe it may have to do with the scope of my variables... Thanks in advance :)

package milsteadgrades;
import java.util.Scanner;

public class MilsteadGrades {


public static void main(String[] args)

{
//Call methods to execute program.
displayInfo();
double numOfgrades = getInput();
double average = getAverage(numOfgrades);
char letgrade = determineLetterGrade(average);
displayGrades(average, letgrade);
}


public static void displayInfo()

{
System.out.println("Mallory Milstead");
System.out.println("This program will prompt the user for a number of 
grades"
+ " and each grade. Then the program calculates and displays the average and 
letter"+" grade.");
}

 public static double getInput()

{
//Prompt user to enter number of grades and assign that number to 
numOfgrades.
System.out.print("How many grades would you like to average? ");
Scanner keyboard = new Scanner(System.in);
double numOfgrades = keyboard.nextDouble();
return numOfgrades;
}

public static double getAverage(numOfgrades)

{
//Prompt the user to enter grades.
System.out.println("Enter exam scores : ");
Scanner keyboard = new Scanner(System.in);
double total = 0;
for (double i = 0; i < numOfgrades; i++) {
double grade = keyboard.nextDouble();
total+=grade;}
double average = total/numOfgrades;
return average;
}

public static char determineLetterGrade(average)

{ double testscore = average;
    char letgrade;

    if (testscore >= 90) 
    {
        letgrade = 'A';
    } else if (testscore >= 80) 
    {
        letgrade = 'B';
    } else if (testscore >= 70) 
    {
        letgrade = 'C';
    } else if (testscore >= 60) 
    {
        letgrade = 'D';
    } else 
    {
        letgrade = 'F';
    }
    return letgrade;
    }

public static void displayGrades(average, letgrade)

{
System.out.println("The average of the grades is "+average+ " and the 
letter grade"+ " is " + letgrade+".");}

}

Beginning with the line -public static double getAverage(numOfgrades)-, I continuously get "cannot find symbol" error message. None of my variables is being recognized.

mal0689
  • 3
  • 4
  • 4
    Possible duplicate of [What does a "Cannot find symbol" compilation error mean?](https://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean) – Juan Carlos Mendoza Dec 04 '17 at 18:18
  • Java is NOT modular language. It is an OBJECT language. Hard to say about elegant, or high quality Java code while programming on static methods (de facto violates OP sense) – Jacek Cz Dec 04 '17 at 18:28
  • Yeah, I am new to this and was a little confused. I should have said implementing methods instead. Thanks for the heads up. – mal0689 Dec 04 '17 at 18:31

1 Answers1

1

You need to declare the type of the argument of getAverage. Like

public static double getAverage(double numOfgrades)

Similiarly for your other methods(not modules). Have a read of this or this for tips.

Karl Reid
  • 2,147
  • 1
  • 10
  • 16
  • Karl Reid... Thank you so much. I knew it was something simple. I did that and it ran like a charm the first time. You saved me a lot of hassle and time. Best Wishes :) – mal0689 Dec 04 '17 at 18:23