I am very confused about what to do with this assignment. I am relatively new to java programming and I have to calculate GPA when given a grade and the corresponding amount of credits in an input file. The exact description is
The first requirement is to "1. Use a method that takes a letter grade and a number of credits as parameters, calculates and returns the points for the course."The course points equal (gradePoints x credits). Write a program that reads data from a text file that contains a sequence of (letter grade, credits) pairs, and calculates the overall GPA of the student. An example of the input may look something like this:
B- 3
D+ 2
A 3
W 0
C+ 4
B 3
My problem currently is that I am unsure how to create a new method after the main and still keep the information from the input file. my code so far is below.
import java.util.Scanner; import java.io.*; public class GPA { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Darrien Kamai"); System.out.println("CPS 180"); String filename = scan.nextLine(); File file = new File(filename); Scanner inputFile = new Scanner(file); String gradePoint, readData; //Read grade and amount credits from data file public static void readData(String grade, int credits) throws IOException { grade = inputFile.nextLine(); credits = inputFile.nextInt(); } }
Any help would be very appreciated as I am completely stuck with the new method. the program is giving an illegal start of expression error