I am trying to make a histogram that represent the number of letter grades that are calculated. So the program reads in a csv file, pulls out the name, average grade and letter grade. From there it creates a histogram based on the letter Grades.
Input:
Alicia Marks,89,90,100,95,75,85,94,100,90,92
Bobby Ricks,98,79,87,79,9,98,7,19,98,78
How output should look like:
Alicia Marks 85.5 B
Bobby Ricks 90.0 A-
A: 1
A-: 1
B+: 2
B: 3
B-: 5
C+: 7
C: 0
C-: 0
D+: 4
D: 0
F: 1
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import java.lang.*;
public class Grades {
public static void main(String[] args) {
Grades x = new Grades();
System.out.println("");
x.histo();
}
public void histo() {
File file3 = new File("scores.csv");
String letter;
double sumNumber = 0.0;
ArrayList<Double> avg = new ArrayList<>();
ArrayList<String> letterGrade = new ArrayList<>();
try {
Scanner scanner = new Scanner(file3);
while (scanner.hasNextLine()) {
String lines = scanner.nextLine();
String[] values = lines.split(",");
// Converts String Array into Double Array
double[] score = new double[values.length - 1];
for (int i = 1; i < values.length; i++) {
score[i - 1] = Double.parseDouble(values[i]);
}
// Finds the sum and then the average, adds it to a array List
double sumNum = 0.0;
for (double i : score) {
sumNum += i;
}
double aver = sumNum / 10;
avg.add(aver);
String letterG;
if( aver < 0.0)
letterG = "F";
else if(aver < 60.0)
letterG = "D";
else if(aver < 67.0)
letterG = "D+";
else if(aver < 70.0)
letterG = "C-";
else if(aver < 73.0)
letterG = "C";
else if(aver < 77.0)
letterG = "C+";
else if(aver < 80.0)
letterG = "B-";
else if(aver < 83.0)
letterG = "B";
else if(aver < 87.0)
letterG = "B+";
else if(aver < 90.0)
letterG = "A-";
else
letterG = "A";
letterGrade.add(letterG);
} //WL
for(int i = 0; i < letterGrade.size(); i++) {
letterGrade.get(i);
String theLetter = letterGrade.get(i);
int current = 1;
if (letterGrade.contains(theLetter)){
int j = current++;
System.out.println(theLetter + "\t" + j);
}
else
System.out.println(theLetter + "\t" + "0");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} //Histo End
} // Class End
So, I can make somewhat of a histogram, but I can't figure out how to get the blank values. So when B has no value, how do I get that to implement. I am also trying to figure out how to replace the numeric values with stars, so that it looks like this
A : *
A-: *
B+: **
B : ***
So any help in fixing this is super appreciated.