Answered step by step
Verified Expert Solution
Question
1 Approved Answer
currently, I am trying to figure out what is wrong with my java code. What is wrong with my java code? import java.util.Arrays; import java.util.Scanner;
currently, I am trying to figure out what is wrong with my java code. What is wrong with my java code? import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.ioFile;
Student data that will be used to show specific values
public class StudentTest private Student students;public static void mainString args
StudentTest test new StudentTest;
test.readInput;
test.sortbyID;
test.writeOutput;
Reading fileinputtxt
public void readInput
try Scanner input new Scanner
System.inString filename input.next;
Scanner fileIn;
try
fileIn new Scannernew Fileinputtxt;
int n fileIn.nextInt;
for int i ; i System.out.printlnLowest Score: lowestScoreName lowestScore ;
Sort students by average score in descending order double avg Arrays.streamstestScoresaverageorElse; System.out.printlnStudents average sorted from highest to lowest:"; double average Arrays.streamstudenttestscoresaverageorElse; System.out.printlnstudentname average;
private void sortbyID System.out.printlnStudent Data sorted by ID:; System.out.printlnstudentid student.name Arrays.toStringstudenttestscores; Student with the highest average score String highestAverageName ; for Student student : students if average highestAverage highestAverageName student.name; Highest and Lowest individual scores with student names int lowestScore Integer.MAXVALUE; String lowestScoreName ; for Student score : students highestScore score; lowestScore score; import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.ioFile;
Student d
import java.ioFileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.ioFile;
Student data that will be used to show specific values
public class StudentTest
private int numStudents;
private Student students;
private int numTests ;
public static void mainString args
StudentTest test new StudentTest;
test.readInput;
test.sortbyID;
test.writeOutput;
Reading fileinputtxt
public void readInput
try Scanner input new ScannerSystemin
System.out.printEnter input file name: ;
String filename input.next;
Scanner fileIn;
try
fileIn new Scannernew Fileinputtxt;
int n fileIn.nextInt;
for int i ; i n; i
int id fileIn.nextInt;
String name fileIn.next;
System.out.printlnid name;
catch FileNotFoundException e
System.err.printlnFile not found: "input.txt;
eprintStackTrace;
Sort students by ID
private void sortbyID
students.sortbyIDComparatorcomparingIntstudent student.id;
System.out.printlnStudent Data sorted by ID:;
for Student student : students
System.out.printlnstudentid student.name Arrays.toStringstudenttestscores;
private int writeOutput
Student with the highest average score
double highestAverage ;
String highestAverageName ;
for Student student : students
double average Arrays.streamstudentname, highestAverageNameaverageorElse;
if average highestAverage
highestAverage average;
highestAverageName student.name;
System.out.printlnHighest Average: highestAverageName;
Highest and Lowest individual scores with student names
int highestScore Integer.MINVALUE;
int lowestScore Integer.MAXVALUE;
String highestScoreName ;
String lowestScoreName ;
for Student student : students
for Student score : students
if score student.highestScore
highestScore score;
highestScoreName student.name;
if score student.lowestScore
lowestScore score;
lowestScoreName student.name;
System.out.printlnHighest Score: highestScoreName highestScore ;
System.out.printlnLowest Score: lowestScoreName lowestScore ;
Sort students by average score in descending order
students.sorts s;
double avg Arrays.streamstestScoresaverageorElse;
double avg Arrays.streamstestScoresaverageorElse;
return Double.compareavg avg;
System.out.printlnStudents average sorted from highest to lowest:";
for Student student : students
double average Arrays.streamstudenttestscoresaverageorElse;
System.out.printlnLowest Score: lowestScoreName....
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started