I am working on a simple program. I am having problems with the lines beginning with two of the lines. The first problem is the line beginning with int.numEntered. The second problem is with my static method generateStats. I'm not sure how to incorporate a method other than the main method in this and then call it later in the code. Does anyone have any suggestions? Thanks!
import javax.swing.*;
public class Assignment5
{
public static void main(String[] args)
{
int[] newArray = new int[counter];//Initializing array
int counter = 0;//Initializing counter to zero
int arrayLength = 0;//Initializing counter to zero
int sum = 0;//Initializing counter to zero
int numArrayElements = 0;
int average = 0;
String input = JOptionPane.showInputDialog ("Please enter a positive integer (enter 0 to generate statistics): "
;
int numEntered = Integer.parseInt(input);
public static generateStats (int sum, counter, int[] newArray){
numArrayElements = counter + 1;
average = sum/numArrayElements;
int[] newArray = new int [numArrayElements];
for (i = 0; i < numArrayElements; i++);{
myArray = newArray;
}
SelectionSort.sort(myArray);
min = myArray[0];
max = myArray[myArray.length() - 1];
}
if (numEntered > 0){//What to do if the input is greater than zero
newArray[counter] = numEntered;
counter ++;
arrayLength = counter + 1;
sum = sum + numEntered;
}
else {
generateStats();
}
JOptionPane.showMessageDialog(
null, "The average is: " + average);
JOptionPane.showMessageDialog(
null, "The minimum is: " + min);
JOptionPane.showMessageDialog(
null, "The maximum is: " + max);
JOptionPane.showMessageDialog(
null, "Click \"OK\" to end program."
;
String junk;
junk = SavitchIn.readLine();//Ending Program
System.exit(0);
}
}
import javax.swing.*;
public class Assignment5
{
public static void main(String[] args)
{
int[] newArray = new int[counter];//Initializing array
int counter = 0;//Initializing counter to zero
int arrayLength = 0;//Initializing counter to zero
int sum = 0;//Initializing counter to zero
int numArrayElements = 0;
int average = 0;
String input = JOptionPane.showInputDialog ("Please enter a positive integer (enter 0 to generate statistics): "
int numEntered = Integer.parseInt(input);
public static generateStats (int sum, counter, int[] newArray){
numArrayElements = counter + 1;
average = sum/numArrayElements;
int[] newArray = new int [numArrayElements];
for (i = 0; i < numArrayElements; i++);{
myArray = newArray;
}
SelectionSort.sort(myArray);
min = myArray[0];
max = myArray[myArray.length() - 1];
}
if (numEntered > 0){//What to do if the input is greater than zero
newArray[counter] = numEntered;
counter ++;
arrayLength = counter + 1;
sum = sum + numEntered;
}
else {
generateStats();
}
JOptionPane.showMessageDialog(
null, "The average is: " + average);
JOptionPane.showMessageDialog(
null, "The minimum is: " + min);
JOptionPane.showMessageDialog(
null, "The maximum is: " + max);
JOptionPane.showMessageDialog(
null, "Click \"OK\" to end program."
String junk;
junk = SavitchIn.readLine();//Ending Program
System.exit(0);
}
}