Read student data from the \"student.txt\" text file. Use (scanner) Calculate th
ID: 3787101 • Letter: R
Question
Read student data from the "student.txt" text file. Use (scanner) Calculate the data as described' and output a textfile named ( Assignment3) use (printWritter) 4 of 5 Smith Richard N 87 Johnson Daniel 73 83 Williams David 60 91 88 85 76 Row of the Text File Contains 67 91 Davis Dorothy N 96 60 92 Student Last Name Miller Jeff N 74 Student First Name Wila William N Athlete Flag Betty 65 59 93 Ya is an athlete Taylor Helen 94 83 N a is not an athlete Anderson Sandra 78 94 91 Quiz Grade Paul Y 58 Jackson Charles N56 92 B6 Grade on Test 1 White Michelle N Grade on Test 2 Harris 86 85 rah N Martin Mary 58 Thompson John N Garcia George 43 35 Student Output For each student read from the file, output the following information to your output file: A Student Number (just use the line number in the file) For example: Richard Smith is t1, Daniel Johnson is H2, etc Student Name (last name, a comma, and first name) Student Athlete Eligibility Output either "N/A "Yes", or"No' If student is not an athlete, output "N/A If student is an athlete, their letter grade (calculation described below) must be a "C" or higher to be eligible to play in the Big Game Note, in the file provided at least 1 student is not eligible to play in the Big Game Student Grades on Quizzes, Test 1, and Test 2 Numerical Grade Average of their Quiz score, Test 1, and Test 2 For example, Richard has an 87 quiz average, 98 on Test 1 and 59 on Test 2 His overall numerical grade is (87+98-59)/3 81-33333 Letter Grade See table on next page Letter Grade Calculation... Letter Grade Fron: To Great than or equal to 90.0 Less than or equal to 100.0 "B" Great than or equal to 80.0 Less than 90.0 Great than or equal to 70.0 Less than 80.0 "D" Great than or equal to 60.0 Less than 70.0 PF" Great than or equal to 0.0 Less than 60.0Explanation / Answer
Please follow the code and comments for description :
CODE :
import java.io.File; // required imports
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;
public class StudentData { // class to run the code
public static void main(String[] args) throws FileNotFoundException, IOException { // driver method
File outFile = new File ("StudentOutput.txt");
PrintWriter pw = new PrintWriter(outFile);
String fname, lname, aFlag, qGrade, t1, t2, lGrade = null; // local variables
double sGrade = 0;
int num = 0;
// read the data from the files to array data
Scanner input = new Scanner(System.in);
System.out.print("Please Enter the Filename : ");
File file = new File(input.nextLine());
input = new Scanner(file);
while (input.hasNextLine()) {
String line = input.nextLine();
num++;
StringTokenizer tkr = new StringTokenizer(line, " ");
lname = tkr.nextToken();
fname = tkr.nextToken();
aFlag = tkr.nextToken();
qGrade = tkr.nextToken();
t1 = tkr.nextToken();
t2 = line.substring(line.lastIndexOf(" ") + 1);
if("".equals(t2) || t2 == null){
t2 = "0";
}
if (aFlag.equalsIgnoreCase("N")) {
aFlag = "N/A";
} else {
aFlag = "Yes";
}
sGrade = (double)(Integer.parseInt(qGrade) + Integer.parseInt(t1) + Integer.parseInt(t2)) / 3; // calculate the grade
if(sGrade >= 0.0 && sGrade < 60.0){ // grade calculator
lGrade = "F";
} else if(sGrade >= 60.0 && sGrade < 70.0){
lGrade = "D";
} else if(sGrade >= 70.0 && sGrade < 80.0){
lGrade = "C";
} else if(sGrade >= 80.0 && sGrade < 90.0){
lGrade = "B";
} else if(sGrade >= 90.0 && sGrade <= 100.0){
lGrade = "A";
}
pw.println(num + " " + lname + ", " + fname + " " + aFlag + " " + sGrade + " " + lGrade); // write the data
}
pw.close();
}
}
OUTPUT :
1 Tim, Smith N/A 54.0 F
2 Diablo, Ho Yes 39.666666666666664 F
3 Tom, Doe Yes 60.666666666666664 D
4 Buffy, Slayer Yes 52.0 F
5 LeRoy, Jackson Yes 44.333333333333336 F
6 Bruce, Lee N/A 55.666666666666664 F
7 Tom, Smith N/A 59.666666666666664 F
8 Dick, Smith N/A 44.666666666666664 F
9 Harry, Ho Yes 49.666666666666664 F
10 Jane, Doe Yes 56.333333333333336 F
Hope this is helpful.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.