I have been trying to trim the and get the length and parse the string into a double from what the user enters. And I think I may have gotten that? Can you tell me if I did this correctly??
The one that I am most concerned with is how do I validate correct grades to be entered? Any valid grades should be anything greater than 0 and grades less than 100.
So far what Ive done is asked the user to enter up to ten grades, I then added in there, if the user presses enter, then they are done entering. Then I would add up the grades and average them up and print it. I haven't added that coding in there yet, as I am still trying to trim, get length and parse the string into a double.
I know, It would make sense to read doubles from the user, but my instructor specifically asked that we read strings then convert to doubles if and only if the user entered a length > 0 of which I already established into my code.
import java.util.*; import java.io.*; public class Grades { public static void main(String[] args)throws IOException { double validGrades = 0; double d = 0; double total = 0; final int SIZE = 10; boolean exit = false; int count = 0; String gradesEntered; BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String[ ] grades = new String[SIZE]; String[ ] trimmedGradesEntered = new String[grades.length]; System.out.println("Please enter up to 10 grades and press enter to finish."); while((count <= SIZE-1) && (exit == false)){ System.out.print("Grade " + (++count) + ": "); gradesEntered = bf.readLine( ).trim(); if(gradesEntered.length() < 1){ exit = true; } else{ total = total + Double.parseDouble(gradesEntered); } } } }