hi folks
the program I am attempting to do here, even though its horrible so far, is one that reads in a file containing:
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 75 63
What needs to be done is to have a value returning method for figuring out the average of each student by adding up the test score and doing the average based on that. There also need to be a void method for displaying the letter grade for each student based on the average that is figured out.
Also, I need to be able to output the information figured out to a file.
This is a sample of what it needs to look like.
Student Test1 Test2 Test3 Test4 Test5 Average Grade
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
…
Class Average =
Now for my horrible code so far.....and btw I cannot use arrays so this needs to be done as simply as possible. And also, I am using a mac so my files that are being read from are kept on a USB as you will see from my input. Not sure why but things don't work with reading on my mac if kept just on the hard drive.
import java.io.*;
import java.util.*;
public class methodLab3
{
public static void main(String[] args) throws FileNotFoundException
{
Scanner inFile = new Scanner(new File("/Volumes/SCII CE USB/tests.txt"));
System.out.println("The average is: " + average(name,tests,total));
double total;
}
public static double average(String name,int tests,double total) throws FileNotFoundException
{
Scanner inFile = new Scanner(new File("/Volumes/SCII CE USB/tests.txt"));
while (inFile.hasNextLine())
{
name = inFile.next();
tests = inFile.nextInt();
total += tests;
}
return total/4;
}
}
public static void displayGrade(double average) throws FileNotFoundException
{
if (average >= 90)
{
System.out.println("A");
}
else if (average >= 80)
{
System.out.println("B");
}
else if (average >= 70)
{
System.out.println("C");
}
else if (average >= 60)
{
System.out.println("D");
}
else
{
System.out.println("F");
}
}
Any help would be very welcome plz.