Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   File/Method/Array grade calculations (http://www.go4expert.com/forums/file-method-array-grade-calculations-t29821/)

Tigers27 20Sep2013 23:24

File/Method/Array grade calculations
 
I'm trying to write this Java program that reads student names and their scores from a file. I have to create 2 methods inside of main that calculate the average grade and determines the appropriate letter value and output that to a separate file. So far I have it able to do the calculations, however I am having problems with the methods (where they go, how to define/call, etc) Obviously, methods have given me a lot of trouble before and are doing it again. I really need help because this assignment is due soon and I have no clue what to do :(

Code:




import java.io.*;
import java.util.*;

public class Lab2_1 {
  public static void main (String[]args)
    throws FileNotFoundException {

    Scanner input = new Scanner(new File("Ch7_Ex14Data.txt")); // reading from file

public static double averageMethod(double test1 + test2 + test3 + test4 + test5){}
public static String letterMethod(double calculateAverage) {

      if (calculateAverage >= 100){
        System.out.println("A");
      }else if(calculateAverage >= 89){
        System.out.println("B");
      }else if (calculateAverage >= 79){
        System.out.println("C");
      }else if (calculateAverage >= 69){
        System.out.println("D");
      }else
        System.out.println("F");

}




    double test1, test2, test3, test4, test5;
    String firstName;
    double calculateAverage;
    calculateAverage=0;

    while (input.hasNext())
    {
      firstName = input.next();
      System.out.print(firstName + "\t");


      test1 = input.nextDouble();
      test2 = input.nextDouble();
      test3 = input.nextDouble();
      test4 = input.nextDouble();
      test5 = input.nextDouble();

      System.out.print((test1 + test2 + test3 + test4 + test5)/5);
      System.out.print("\t");

    double average= averageMethod(test1 + test2 + test3 + test4 + test5)/5.0;
    double letter = letterMethod(return calculateAverage);

    }
    input.close();
    }
}







]



All times are GMT +5.5. The time now is 23:21.