getting error when i run this not sure how to fix it, errors are at the bottom a
ID: 3646422 • Letter: G
Question
getting error when i run this not sure how to fix it, errors are at the bottom above is the requirements and codeWrite an application program that reads in a list of integer numbers and print out the sum of all numbers, the average, the lowest and the highest value entered. The first input number indicates how many numbers the program is going to read. For example, if the first number entered is 5, then it means five integer numbers will be expected as input. Display your result in an output dialog box.
Run/test you program with at least 5 input numbers.
import java.io.*;
import javax.swing.JOptionPane;
class test
{
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
String firstNumber;
int size,sum=0;
double average=0;
firstNumber = JOptionPane.showInputDialog ( "Enter the number of integers" );
size=Integer.parseInt ( firstNumber);
int a[]=new int[size];
System.out.println("Enter values");
for(int i=0;i<size;i++)
a[i]=scan.nextInt(System.in);
int min=a[i],max=a[i];
for(i=0 ;i<size;i++)
{
sum=sum+a[i];
if(a[i]<min)
min=a[i];
if(a[i]>max)
max=a[i];
}
average=(sum/size);
JOptionPane.showMessageDialog(null,"result:"+sum+min+max+average);
}
}
error
test.java:7: error: cannot find symbol
Scanner scan=new Scanner(System.in);
^
symbol: class Scanner
location: class test
test.java:7: error: cannot find symbol
Scanner scan=new Scanner(System.in);
^
symbol: class Scanner
location: class test
test.java:24: error: cannot find symbol
int min=a[i],max=a[i];
^
symbol: variable i
location: class test
test.java:24: error: cannot find symbol
int min=a[i],max=a[i];
^
symbol: variable i
location: class test
test.java:25: error: cannot find symbol
for(i=0 ;i<size;i++)
^
symbol: variable i
location: class test
test.java:25: error: cannot find symbol
for(i=0 ;i<size;i++)
^
symbol: variable i
location: class test
test.java:25: error: cannot find symbol
for(i=0 ;i<size;i++)
^
symbol: variable i
location: class test
test.java:27: error: cannot find symbol
sum=sum+a[i];
^
symbol: variable i
location: class test
test.java:28: error: cannot find symbol
if(a[i]<min)
^
symbol: variable i
location: class test
test.java:29: error: cannot find symbol
min=a[i];
^
symbol: variable i
location: class test
test.java:30: error: cannot find symbol
if(a[i]>max)
^
symbol: variable i
location: class test
test.java:31: error: cannot find symbol
max=a[i];
^
symbol: variable i
location: class test
12 errors
Explanation / Answer
Please try the following code. It will clear each and every thing to you. "import java.util.Arrays; /** This class computes the alternating sum of a set of data values. */ public class DataSet { private double[] data; private int dataSize; /** Constructs an empty data set. */ public DataSet() { final int DATA_LENGTH = 100; data = new double[DATA_LENGTH]; dataSize = 0; } /** Adds a data value to the data set. @param x a data value */ public void add(double x) { if (dataSize == data.length) data = Arrays.copyOf(data, 2 * data.length); data[dataSize] = x; dataSize++; } /** Gets the alternating sum of the added data. @return sum the sum of the alternating data or 0 if no data has been added */ public double alternatingSum() { . . . } } I have to use the following class as the tester class: /** This program calculates an alternating sum. */ public class AlternatingSumTester { public static void main(String[] args) { DataSet data = new DataSet(); data.add(1); data.add(4); data.add(9); data.add(16); data.add(9); data.add(7); data.add(4); data.add(9); data.add(11); double sum = data.alternatingSum(); System.out.println("Alternating Sum: " + sum); System.out.println("Expected: -2.0"); } } "
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.