Question
Here's a Java program that reads the data from the studentdata.txt file, creates two arrays for S-number and GPA, calculates the class rank for each
Here's a Java program that reads the data from the "studentdata.txt" file, creates two arrays for S-number and GPA, calculates the class rank for each student, and generates a histogram showing the distribution of GPAs across eight categories:
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;
public class StudentDataAnalyzer { public static void main(String[] args) { int[] histogram = new int[8]; // stores the count of students in each GPA category String[] sNumbers = new String[1000]; // stores the S-numbers of the students double[] gpas = new double[1000]; // stores the GPAs of the students // read the data from the file try { Scanner scanner = new Scanner(new File("studentdata.txt")); int i = 0; while (scanner.hasNextLine()) { String line = scanner.nextLine(); String[] fields = line.split(","); sNumbers[i] = fields[0]; gpas[i] = Double.parseDouble(fields[1]); i++; } scanner.close(); } catch (FileNotFoundException e) { System.out.println("File not found: " + e.getMessage()); System.exit(1); } // calculate the class rank for each student int[] ranks = new int[1000]; for (int i = 0; i < gpas.length; i++) { int betterCount = 0; for (int j = 0; j < gpas.length; j++) { if (gpas[j] > gpas[i]) { betterCount++; } } ranks[i] = betterCount + 1; } // generate the histogram for (int i = 0; i < gpas.length; i++) { if (gpas[i] >= 0 && gpas[i] < 0.5) { histogram[0]++; } else if (gpas[i] >= 0.5 && gpas[i] < 1.0) { histogram[1]++; } else if (gpas[i] >= 1.0 && gpas[i] < 1.5) { histogram[2]++; } else if (gpas[i] >= 1.5 && gpas[i] < 2.0) { histogram[3]++; } else if (gpas[i] >= 2.0 && gpas[i] < 2.5) { histogram[4]++; } else if (gpas[i] >= 2.5 && gpas[i] < 3.0) { histogram[5]++; } else if (gpas[i] >= 3.0 && gpas[i] < 3.5) { histogram[6]++; } else if (gpas[i] >= 3.5 && gpas[i] <= 4.0) { histogram[7]++; } } // display the histogram System.out.println("Histogram of GPAs:"); System.out.println("0.0 to 0.49 (" + histogram[0] + ") " + repeat("*", histogram[0]/10)); System.out.println("0.5 to 0.99 (" + histogram[1] + ") " + repeat("*", histogram[1]/10)); System.out.println("1.0 to 1.49 (" + histogram[2] + ") " + repeat("*", histogram[2]/10)); System.out.println("1.5 to 1
This code does not work properly in netbeans can someone try the code in their own ide to see if it works then give me an explaination on what to do
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