Answered step by step
Verified Expert Solution
Link Copied!

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.io.File;
/** Student data that will be used to show specific values */
public class StudentTest {private Student[] students;public static void main(String[] args){
StudentTest test = new StudentTest();
test.readInput();
test.sortbyID();
test.writeOutput();}
/** Reading file(input.txt)*/
public void readInput(){
try (Scanner input = new Scanner(
System.in)){String filename = input.next();
}
Scanner fileIn;
try {
fileIn = new Scanner(new File("input.txt"));
int n = fileIn.nextInt();
for (int i =0; i System.out.println("Lowest Score: "+ lowestScoreName +"("+ lowestScore +")");
// Sort students by average score in descending order { double avg2= Arrays.stream(s2.testScores).average().orElse(0); System.out.println("Students average sorted from highest to lowest:"); double average = Arrays.stream(student.testscores).average().orElse(0); System.out.println(student.name +""+ average);}
} private void sortbyID(){ System.out.println("Student Data sorted by ID:"); System.out.println(student.id +""+ student.name +""+ Arrays.toString(student.testscores));}// 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.MAX_VALUE; 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.io.File;
/** Student d
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.io.File;
/** Student data that will be used to show specific values */
public class StudentTest {
private int numStudents;
private Student[] students;
private int numTests =4;
public static void main(String[] args){
StudentTest test = new StudentTest();
test.readInput();
test.sortbyID();
test.writeOutput();
}
/** Reading file(input.txt)*/
public void readInput(){
try (Scanner input = new Scanner(System.in)){
System.out.print("Enter input file name: ");
String filename = input.next();
}
Scanner fileIn;
try {
fileIn = new Scanner(new File("input.txt"));
int n = fileIn.nextInt();
for (int i =0; i n; i++){
int id = fileIn.nextInt();
String name = fileIn.next();
System.out.println(id +""+ name);
}
} catch (FileNotFoundException e){
System.err.println("File not found: "+ "input.txt");
e.printStackTrace();
}
}
// Sort students by ID
private void sortbyID(){
students.sortbyID(Comparator.comparingInt(student -> student.id));
System.out.println("Student Data sorted by ID:");
for (Student student : students){
System.out.println(student.id +""+ student.name +""+ Arrays.toString(student.testscores));
}
}
private int writeOutput(){
// Student with the highest average score
double highestAverage =0;
String highestAverageName ="";
{
for (Student student : students){
double average = Arrays.stream(student.name, highestAverageName).average().orElse(0);
if (average > highestAverage){
highestAverage = average;
highestAverageName = student.name;
}
}
System.out.println("Highest Average: "+ highestAverageName);
// Highest and Lowest individual scores with student names
int highestScore = Integer.MIN_VALUE;
int lowestScore = Integer.MAX_VALUE;
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.println("Highest Score: "+ highestScoreName +"("+ highestScore +")");
System.out.println("Lowest Score: "+ lowestScoreName +"("+ lowestScore +")");
// Sort students by average score in descending order
students.sort(s1, s2);
{
double avg1= Arrays.stream(s1.testScores).average().orElse(0);
double avg2= Arrays.stream(s2.testScores).average().orElse(0);
return Double.compare(avg2, avg1);
System.out.println("Students average sorted from highest to lowest:");
for (Student student : students){
double average = Arrays.stream(student.testscores).average().orElse(0);
System.out.println("Lowest Score: "+ lowestScoreName....
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions