Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have this code: import java.util.*; import java.io.*; public class lab9Prob14

ID: 3641126 • Letter: I

Question

I have this code:

import java.util.*;
import java.io.*;

public class lab9Prob14
{
public static void main(String[] args) throws FileNotFoundException
{

Scanner inFile = new Scanner(new FileReader ("students.txt"));
PrintWriter outFile = new PrintWriter("output.txt");
double classSum = 0;
int studentCount = 0;
double classAverage = 0;
DoubleClass studentAvg = new DoubleClass();
outFile.println("Student Test1 Test2 Test3 Test4 Test5 Average Grade");

while(inFile.hasNext())
{
studentCount++;
calculateAverage(inFile, outFile, studentAvg);
classSum += studentAvg.getNum();
}

if (studentCount > 0)
classAverage = classSum / studentCount;
outFile.println(" Class Average = " + classAverage);
inFile.close();
outFile.close();
}
public static void calculateAverage(Scanner iFile, PrintWriter oFile, DoubleClass studentAverage)
{
String name;
int test;
double average;
String grade;
int sum;
sum = 0;
name = iFile.next();
oFile.printf("%-9s ", name);

for (int count = 0; count < 5; count++)
{
test = iFile.nextInt();
oFile.printf("%4d ", test);
sum = sum + test;
}
average = sum/5.0;
studentAverage.setNum(average);
grade = calculateGrade(average);
oFile.printf("%5.1f %3s", average, grade);
oFile.printf("%n");
}
private static String calculateGrade(double average)
{

if (average >= 90)
return "A";
else if (average >= 80)
return "B";
else if (average >= 70)
return "C";
else if (average >= 60)
return "D";
else
return "F";
}
}
With a seperate DoubleClass:

public class DoubleClass
{

double doubleNum;

public DoubleClass()
{
doubleNum = 0.0;
}
public DoubleClass(double num)
{
doubleNum = num;
}
public double getNum()
{
return doubleNum;
}

public void setNum(double num)
{
doubleNum = num;
}
}

And an inFile and outFile txt:

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

It all compiles, but nothing shows up on the command prompt except "Press any key to continue...".
Can somebody please tell me where my mistake is?


Explanation / Answer

Your Program Retrieves the students value from a file named "Student.txt" and performs calculation for Average and grade and stores it in a file called output.txt. Please check in your project folder for a file name output.txt. There is no console output for this program, so you did not get any output in the command prompt. The output file which should be stored in the project folder is given below which will be automatically created when the program is exceuted. output.txt Student Test1 Test2 Test3 Test4 Test5 Average Grade Johnson 85 83 77 91 76 82.4 B Aniston 80 90 95 93 48 81.2 B Cooper 78 81 11 90 73 66.6 D Gupta 92 83 30 69 87 72.2 C Blair 23 45 96 38 59 52.2 F Clark 60 85 45 39 67 59.2 F Kennedy 77 31 52 74 83 63.4 D Bronson 93 94 89 77 97 90.0 A Sunny 79 85 28 93 82 73.4 C Smith 85 72 49 75 63 68.8 D Class Average = 70.94 Hope it helps. Please rate if it helps.