How to output values of an array?
<p>I am trying to output the value of an array called <code>gradeList</code>. I have 2 classes, <code>Grades</code>, and <code>GradesTester</code>.I am including my code so far - my compiler is reporting that it has 11 errors, mostly having to do with the Scanner chopper line, and the <code>double[] grades = new double[]</code> line. Please tell me what I am doing wrong and how I can fix it. Thanks</p>

<p>GradeTester:</p>

<pre><code>public class GradesTester {

    public static void main(String args[]) {
        Grades test = new Grades("5 - 90 85 95.5 77.5 88");
        out.println(test);
        out.println("sum = " + test.getSum());
        out.println("num grades = " + test.getNumGrades());
        out.println("low grade = " + test.getLowGrade());
        out.println("high grade = " + test.getHighGrade());
    }
}
</code></pre>

<p>Grades:</p>

<pre><code>public class Grades {

    private double[] grades;

    public Grades() {
        setGrades("");
    }

    public Grades(String gradeList) {
        // here we just pass the gradeList on to the setGrades method
        setGrades(gradeList);
    }

    public void setGrades(String gradeList) {
        // gradeList will look something like this  "5 - 90 85 95.5 77.5 88"

        // so put this gradeList into a Scanner object 
        Scanner chopper = new Scanner(Grades.toString(gradeList));

        // now get the number of grades (5 in this example)
        int numGrades = chopper.nextInt();

        // now, create the array object
        double[] grades = new double["5 - 90 85 95.5 77.5 88"];

        // next, we need to move past the -
        // notice the line below does just this, since we get the next element out of the scanner
        chopper.nextDouble();

        // now loop through the rest of the elements (which are the grades)
        // and put them into the grades array

        int i = 0;
        while (chopper.hasNextDouble()) {
            out.println(chopper.nextDouble());
        }
    }
}
</code></pre>
