I have been trying to trim the and get the length and parse the string into a double from what the user entered to no avail. Any help would be much appreciated. Please bear with me as I am still very new to Java.
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.
So I am having troubles trying to trim, get length then parsing into doubles, if you could help me with that, that would be great!
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) && (exit == false)){ System.out.print("Grade " + (++count) + ": "); gradesEntered = bf.readLine( ) ; if(gradesEntered.length() < 1){ exit = true; } } } }