JAVA- Write a program that reads in a series of student names and exam scores, t
ID: 3803780 • Letter: J
Question
JAVA- Write a program that reads in a series of student names and exam scores, then adjusts thescores on a curve. The highest score should be increased to 100.0 and all other scores increasedby the same number of points. For example, a series of 2 scores 89.0 and 83.0 will become100.0 and 94.0, respectively (each increased by 11.0). A series of 2 scores 68.0 and 61.0 wouldbecome 100.0 and 93.0, respectively. The program should print out each student’s name, rawscore, and adjusted score.
Notes
You will need to utilize arrays in this program. The input file will begin with a single integer n, followed by n records. Each recordconsists of a single string (student name) and a decimal value (exam score). Format all exam scores to 2 decimal places.
Example input/output:
This is the code I was given, but is there any way to simplify it? We have not gone over many things in this example, such as BufferedReader, and " try{ ". Please make the code as simple as possible so I can understand it. Also include a while loop to continue reading through the input file until all the data has been read through. You can also take out the references to the file name since I DO NOT want it hard coded into the code.
Sample input/Output File in dat Johnson 93.5 Dirks 75.0 Timm 87.0 Faulk 55.5 Miser 69.0 cution Student Name Raw Score ith Curve Johnson 93.50 100.00 Dirks 75.00 50 87.00 93.50 Timm 55.50 62.00 Faulk 69 00 75.50Explanation / Answer
//Note:
//please change the input & output file location in main method before executing the program.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class StudentCurveCalculator {
//Note please change the input & output file locatin in main method before executing the program.
private static void displayStudentCurveFromFile(String inputFileLocation,String outputFileLocation){
FileReader fr=null;
BufferedWriter bw=null;
FileWriter fw=null;
BufferedReader br=null;
try {
fr = new FileReader(inputFileLocation); //creating fileReader object from input file location
br = new BufferedReader(fr);
fw=new FileWriter(outputFileLocation); //creating fileWriter object from input file location
bw=new BufferedWriter(fw);
bw.write(String.format(" %20s %10s %10s", "Student Name", "Raw Score"," With Curve ")); //using string.format to printing header in output file
String line=br.readLine(); //it will store first line from input file which is 5 here and of no use so ignoring it
int lineCounter=0;
float curveDiff=0;
while ((line = br.readLine()) != null) {
lineCounter++;
String[] str=line.split(" "); //Splitting the line on space basis and storing it into an string array
String studentName=str[0]; //storing student name in studentName variable
float rawScore=Float.parseFloat(str[1]); //converting rawScore to float as by default it will be string
if(lineCounter==1){
curveDiff=100-rawScore; //only one time we need to calculate the curveDiff so putting if condition and it will be executed once
}
float withCurve=rawScore+curveDiff; //adding curveDiff to rawScore for calculating withCurve score.
bw.write(String.format(" %20s %10.2f %10.2f", studentName, rawScore,withCurve)); //using string.format to formatting the output,
//.2f is used for restrict upto 2 decimal places
}
}
catch (IOException e)
{
e.printStackTrace();
}finally{
try {
fr.close();//closing the resources as it not required now.
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
String inputFileLocation="C:\ZSampleTest\src\main\java\input.txt"; // path to input.txt file
String outputFileLocation="C:\ZSampleTest\src\main\java\output.txt"; // path to output.txt file
displayStudentCurveFromFile(inputFileLocation,outputFileLocation);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.