1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

File/Method/Array grade calculations

Discussion in 'Java' started by Tigers27, Sep 20, 2013.

  1. Tigers27

    Tigers27 New Member

    Joined:
    Sep 20, 2013
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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();
        }
    }
    
    
    
    
    
    
    
    ]
    
    
    
    
    
     

Share This Page