Note that there are some explanatory texts on larger screens.

plurals
  1. POProgram doesn't compile correctly
    primarykey
    data
    text
    <p>Program is supposed to take the numbers from the numberList and calculate the average and frequency. I have written my code below. I have the main class which I'm also posting as well. I know I can use the an array but I want to try a numberlist instead.</p> <pre><code>import java.io.*; import java.lang.Math; import java.util.*; import java.text.DecimalFormat; public class intNode { double average; double deviation; int sum = 0; int number = 0; int newnumber = 0; int index; double frq; //ArrayList&lt;Integer&gt; element = new ArrayList&lt;Integer&gt;(); int[] rangeFrequency = new int[10]; NumberList numList = new NumberList(51,52,55,57,58,61,62,63,66,66,66,70,72,73,74,75,75,77,77,78,79,81,82,84,86,87,88,91,94,97); DecimalFormat fmt = new DecimalFormat("0.000"); // Start methods public String intAdd (){ while (numList.hasNextInt()) { element.add(numList.nextInt()); } } public int sum (){ for (int item : element){ sum += item; System.out.println(item); } return sum; } public double avg (){ average = sum / element.size(); return average; } public double deviation(){ for (int i = 0; i &lt; element.size(); i++) { newnumber += Math.pow((element.get(i) - average),2); } deviation = Math.sqrt(newnumber / (element.size())); return deviation; } public String frequency(){ //int[] rangeFrequency = new int[10]; for (int elem: element) { int bucket = elem / 10; rangeFrequency[bucket] += 1; } } public String toString() { String result = ""; result += "The average of these grades is : " + fmt.format(average); result += "The standard deviation of these grades is: " + fmt.format(deviation); result += "Grade Range\tFrequency"; for (int i = 0; i &lt; rangeFrequency.length; ++i) { result += (i * 10 + "-" + (i * 10 + 9)); result += ("\t\t" + rangeFrequency[i]); } } } </code></pre> <p>MAIN CLASS BELOW.</p> <pre><code>import java.io.*; import java.lang.Math; import java.util.*; import java.text.DecimalFormat; public class gradeSorter{ public static void main(String[] args) throws IOException { { intNode good = new intNode(); } } } </code></pre> <p>These are the errors I get</p> <pre><code>----jGRASP exec: javac -g gradeSorter.java intNode.java:25: error: cannot find symbol while (numList.hasNextInt()) ^ symbol: method hasNextInt() location: variable numList of type NumberList intNode.java:27: error: cannot find symbol element.add(numList.nextInt()); ^ symbol: method nextInt() location: variable numList of type NumberList intNode.java:27: error: cannot find symbol element.add(numList.nextInt()); ^ symbol: variable element location: class intNode intNode.java:32: error: cannot find symbol for (int item : element){ ^ symbol: variable element location: class intNode intNode.java:40: error: cannot find symbol average = sum / element.size(); ^ symbol: variable element location: class intNode intNode.java:45: error: cannot find symbol for (int i = 0; i &lt; element.size(); i++) ^ symbol: variable element location: class intNode intNode.java:47: error: cannot find symbol newnumber += Math.pow((element.get(i) - average),2); ^ symbol: variable element location: class intNode intNode.java:49: error: cannot find symbol deviation = Math.sqrt(newnumber / (element.size())); ^ symbol: variable element location: class intNode intNode.java:57: error: cannot find symbol for (int elem: element) { ^ symbol: variable element location: class intNode 9 errors ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload