Question

JAVA Question a) Read a file named testScoreIn.txt representing test scores for a class of students....

JAVA Question

a)
Read a file named testScoreIn.txt representing test scores for a class of students.
Each record contains an id number and three test scores (Note: the test scores are integers).
For example, a student record might look like:
BK1234 87 72 91

b)
Without using an array, read each student’s information, one record at a time and compute the student’s average (as a double).

c)
Write to an output file, testScoreOut.txt, as a neatly formatted table with column headings, each student's id, three grades and average grade (as a real number to 3 decimal places)

d)
At the end, when the the sentinel ID, "LastID", is read, print to the screen the id number of the student with the highest average.

Homework Answers

Answer #1

Code:-

Main.java

import java.io.File;
import java.util.Scanner;
import java.io.FileWriter;
import java.io.IOException;
class Main{

public static void main (String[] args) throws Exception,IOException{

//for reading each line from textScoreIn.txt

File file_in = new File("textScoreIn.txt");
Scanner sc = new Scanner(file_in);

FileWriter fw = new FileWriter("textScoreOut.txt");

String id_1="";

Double avg=Double.valueOf(0);

while (sc.hasNextLine()){

String id=sc.next();

int f = sc.nextInt();

int s = sc.nextInt();

int t = sc.nextInt();

Double average =(Double.valueOf(f)+Double.valueOf(s)+Double.valueOf(t))/3;

if(average>avg){ //To get the maximum average and id

id_1=id;

avg=average;

}

String p=id+" "+String.valueOf(f)+" "+String.valueOf(s)+" "+String.valueOf(t)+" "+Double.toString(average)+"\n";

fw.write(p);

}

sc.close();

fw.close();

  

System.out.println("The Student ID having the highest average is");

System.out.println(id_1);

}

}

Output:-

Screenshot of Code:-

textScoreIn.txt

if u like my answer then please give a thumbs up..!!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java: A teacher has five students who have taken four tests. The teacher uses the following...
Java: A teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to a student, based on the average of his or her four test scores: Test Score Letter Grade 90–100 A 80–89 B 70–79 C 60–69 D 0–59 F Write a class that uses a String array (or an ArrayList object) to hold the five students’ names, an array of five characters to hold the five students’ letter...
Consider the following list contained in file named input.txt: using java program Khaled 65 78 56...
Consider the following list contained in file named input.txt: using java program Khaled 65 78 56 89 -999 Kamal 37 55 44 22 18 56 26 -999 Ali 66 33 87 66 87 25 39 78 -999 Taher 12 67 -999 Write a program to read this information and Output the name and sum for each person. Note: the number of rows may vary. Assum -999 as sentenital value
You are to write a program that will process students and their grades. For each student...
You are to write a program that will process students and their grades. For each student the program will read in a student’s name. It should also read in 10 test scores for the student and calculate his or her average. You must read the scores using a loop. The program should output the student’s name, average and letter grade. The average should be displayed accurate to 1 decimal digit. Letter grades are assigned based on the scale: 90-100    A...
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice)....
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice). This program will read in three integers with Scanner, put the values in an array of int, and then print the product of the three values. Example output of the program is shown below, with user input shown in bold: Enter first integer: 3 Enter second integer: 4 Enter third integer: 5 Product: 60 More details about the method you need to write are...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into an array and copy the integers from the array into a Binary Search Tree (BST). The program prints out the following: The number of comparisons made to search for a given integer in the BST And The number of comparisons made to search for the same integer in the array Question 3 Run the program developed in Question 2 ten times. The given values...
we will be taking data in as a file. you cannot use the data values in...
we will be taking data in as a file. you cannot use the data values in your source file but you must read in everything into variables and use it from there. First we need to include <fstream> at the top of our file. We will need to create an input file stream to work and ifstream. ifstream is a datatype. Create a variable with the datatype being ifstream. Variable is drfine by using the member accessor operator to call...
C++ //StudentDataStructure.txt //Student records are stored in a parallel-array Data Structure. Here is the code to...
C++ //StudentDataStructure.txt //Student records are stored in a parallel-array Data Structure. Here is the code to generate and populate Parallel-Array Data Structure: const int NG = 4; //Number of Grades string names[] = {"Amy Adams", "Bob Barr", "Carla Carr", "Dan Dobbs", "Elena Evans" }; int exams[][NG]= { {98,87,93,88}, {78,86,82,91}, {66,71,85,94}, {72,63,77,69}, {91,83,76,60} };    --------------------------------------------------------------------------------- 1 A) Create and Populate a Parallel-Array Data Structure using the code described in "StudentDataStructure.txt". B) Define a Record Data Structure for student records. It...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you start doing anything… This project involves implementing a simple university personnel management program. The program contains two different kinds of objects: students and faculty. For each object, the program stores relevant information such as university ID, name, etc. Different information is stored depending on the type of the object. For example, a student has a GPA, while a faculty has a title and department...