Description

This assignment is a modification of the last assignment. In this assignment, you will input from a file called in.txt and output to a file called out.txt. Otherwise, the assignment will behave the same way as the last assignment.

For doing this assignment, the statement doing input and output will be changed. Otherwise, the code will mostly remain unchanged.

Creating Text IO Files

In Eclipse, using the file menu, you can create the file in.txt in your project. The output file out.txt will be automatically created when you write to it in your program.

To make the file name out.txt show up in the package view in the left pane after program execution do the following:

Click on the project name in the package view in the left pane. Click F5 to refresh contents.

The file name out.txt will show up in above package view if your program created it during execution.

Testing

Input

The in.txt file should contain the following:

15
1, John Adam, 3, 93, 91, 100, Letter
2, Raymond Woo, 3, 65, 68, 63, Letter
3, Rick Smith, 3, 50, 58, 53, Letter
4, Ray Bartlett, 3, 62, 64, 69, Letter
5, Mary Russell, 3, 93, 90, 98, Letter
6, Andy Wong, 3, 89,88,84, Letter
7, Jay Russell, 3, 71,73,78, Letter
8, Jimmie Wong, 3, 70,77,72, Letter
9, Jackie Chan, 3, 85,89,84, Letter
10, Susan Wu, 3, 80,88,84, Letter
11, Bruce Lee, 4, 74, 79, 72, 75, Credit
12, Chuck Norris, 5, 63, 64, 62, 60, 68, Credit
13, Jet Li, 3, 85, 83, 89, Credit
14, Jessica Lauser, 3, 82, 84, 87, Letter
15, Mahnoosh Nik-Ahd, 2, 98, 99, Letter

In the above data, in the first line, 15 is the number of students.

Each subsequent line contains one student data.

For example, the second line contains the first student data where: 1 is id, John Adam is name, 3 is the number of exam taken, 93, 91, 100 are individual exam scores and Letter is grade type.

Output

After running the program, out.txt file should contain the following:

1 John Adam (A)
5 Mary Russell (A)
15 Mahnoosh Nik-Ahd (A)
6 Andy Wong (B)
9 Jackie Chan (B)
10 Susan Wu (B)
14 Jessica Lauser (B)
7 Jay Russell (C)
8 Jimmie Wong (C)
2 Raymond Woo (D)
4 Ray Bartlett (D)
3 Rick Smith (F)
11 Bruce Lee (CR)
13 Jet Li (CR)
12 Chuck Norris (NCR)

Sample Code

//The sample code below input student data from file “in.txt”
//and output student data in file “out.txt”

import java.io.*;
import javax.swing.*;

public class TestStudentExt
{
/*
To make File IO compile, add the phrase: throws Exception
at the end of the method header of the method in which do file IO.
Below, we do File IO in method main, so we added the phrase: throws Exception
*/
public static void main(String[] args) throws Exception
{
String in, outAll, line;
int studentCount;

//Create a BufferedReader object for inputting from a file in.txt
BufferedReader br = new BufferedReader(new FileReader("in.txt"));

//Create a PrintWriter object for outputting to a file out.txt.
PrintWriter pw = new PrintWriter (new FileWriter("out.txt"));

//input the first line of the file containing the number a number that specifies the number of students
in = br.readLine();
studentCount = Integer.parseInt(in);


//Set up a for loop that, in each pass through the loop, will input one student data, tokenize the data,
//and create the corresponding StudentExt object

out = "Student report:n";
for (int i=0; i {
//read one line containing one student data.
in = br.readLine();

//Create a StringTokenizer object to tokenize one student data.

//create the corresponding StudentExt object

}

//String variables for accumulating output lines
String outA="", outB="", outC="", outD="", outF="", outCr="", outNcr="";
String outAll;

//Set up a for loop that, in each pass through the loop, will find grade of one student data,
//and depending on the grade, add a line of output to the corresponding output variable
for (int i=0; i {
//Find one student grade


//Depending on the grade, accumulate a line of output to the corresponding String variable



}

//Concatenate all student output in a single String (say outAll)
outAll=outA+outB+outC+outD+outF+outCr+outNcr;

//Output outAll String to the the out using PrintWriter object.
//make sure to also call flush( ) after calling println()
pw.println(outAll);
pw.flush();

//Call close on File IO objects.
if (br != null)
br.close();
if (pw != null)
pw.close();
}
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.