Home Returning/Passing Variables in Java
Reply: 1

Returning/Passing Variables in Java

mal0689 Published in 2017-12-04 18:15:54Z

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.
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 
+ " 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 
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();
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.

Karl Reid
Karl Reid Reply to 2017-12-04 18:17:53Z

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.306572 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO