Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
I have been fighting with this all day, I can't seem to get my output to come up correctly. This is what I have for now...
import java.io.*;
import java.util.*;
public class Ch7Prob14
{
public static void main(String[] args) throws FileNotFoundException
{
//Declaring Variables
String name;
DoubleClass courseAvg = new DoubleClass();
double gradeString;
double total;
int counter;
char calculateGrade;
//Initializing in/outFile statements
Scanner inFile = new Scanner(new FileReader("Ch7_Ex14Data.txt"));
PrintWriter outFile = new PrintWriter("Ch7_Ex14out.txt");
counter = 0;
gradeString = 0;
total = 0;
//Print Headings to outFile statement
outFile.println("Student Test1 Test2 Test3 Test4 Test5 Average Grade");
//Start of Loop
while (inFile.hasNextLine())
{
//Initializing Variables
name = inFile.nextLine();
gradeString = inFile.nextDouble();
counter++;
total = total + gradeString;
outFile.printf("%-10s", name);
calculateAverage(inFile, outFile, courseAvg);
}
//outFile.println(calculateGrade(avg)); <----Won't work either
outFile.close();
}
public static void calculateAverage(Scanner inFile, PrintWriter outFile,
DoubleClass cAvg)
{
double totalGrades = 0.0;
double score = 0;
score = inFile.nextDouble();
totalGrades = totalGrades + score;
cAvg.setNum(totalGrades / 5);
}
public static char calculateGrade(double avg)
{
if (avg >= 90)
return 'A';
else if (avg >= 80 && avg <= 89)
return 'B';
else if (avg >= 70 && avg <= 79)
return 'C';
else if (avg >= 60 && avg <= 69)
return 'D';
else
return 'F';
}
} And this is my output...
lol, now I am not getting an output...I am so tired. If anyone can help, I would appreciate it.