I need to create a program that will read from a file and output the information into a JFrame. I know how to create a program to read a file, but I just need some help reading the file to GUI. Any help would be appreciated!
package ism3230_ch6assignment;
import java.io.*;
import java.util.*;
public class ISM3230_Ch6Assignment {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
throws FileNotFoundException
{
/**
* declaration of variables
*/
int counter;
double TestAvg = 0;
double classAvg = 0;
String name;
char grade;
/**
* input and output file names
*/
Scanner inFile = new Scanner(new FileReader("612TestScores.txt"));
PrintWriter outFile = new PrintWriter("612TestScoresout.txt");
/**
* will print column headers in output file
*/
outFile.println("Student Test1 Test2 Test3 Test4 Test5 Average Grade");
/**
* while loop reads the data from the input file
*/
while (inFile.hasNext())
{
/**
* reads the student's name from the input file and outputs it in the outFile
*/
name = inFile.next();
outFile.printf("%-10s", name);
TestAvg = calculateAverage(inFile, outFile);
outFile.printf("%6.2f ", TestAvg);
classAvg = classAvg + TestAvg;
grade = calculateGrade(TestAvg);
outFile.printf("%3s%n", grade);
}
classAvg = classAvg / 10;
outFile.println();
outFile.println("Class Average = " + classAvg);
outFile.close();
}
/**
* Void method calculateAverage determines each student's average from the 5
* test scores and displays the average in the output file.
*/
public static double calculateAverage(Scanner inF, PrintWriter outF)
{
int score;
int sum = 0;
int count;;
for (count = 1; count <= 5; count++)
{
score = inF.nextInt();
outF.printf("%4d ", score);
sum = sum + score;
}
return sum / 5.0;
}
/**
* Value-returning method calculateGrade determines student's grade from input
* data and returns each student's grade in the output file.
*/
public static char calculateGrade(double avg)
{
if (avg >= 90)
return 'A';
else if (avg >= 80)
return 'B';
else if (avg >= 70)
return 'C';
else if (avg >= 60)
return 'D';
else
return 'F';
}
}