If I close off the for loop it works but I need to get the output to show as a dialog box as well.
I need the output to show inside a dialog box:
Output should include count of numbers entered
the sum of the numbers
the average of the numbers
and the number closest to the average
This is what I have so far:
package project.pkg2a;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Project2a {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double array[] = new double[10];
//Have user input 10 numbers
for (int counter = 0; counter < 10; counter++){
String userInput =
JOptionPane.showInputDialog(null, "Please, enter a new number",
"Question to User.",
JOptionPane.QUESTION_MESSAGE);
for(int count = 0; count< array.length; count++ ){
array[count] = input.nextDouble();
String output = ("Here are the numbers you selected: " + userInput);
JOptionPane.showMessageDialog(null, output);
}
}
}
}
This is an outline of how it should look:
import javax.swing.JOptionPane;
public class Project2 {
public static void main(String[] args) {
//Method to get user data
//code to display results
String message = display(numbersArray, count);
JOptionPane.showMessageDialog(null, message);
}
//Method to find the sum
public static int find_sum(int[] value){
return (total);
}
//method to find the average
public static double find_avg(int[] values, double count){
return (average);
}
//method to find the closest to the average
public static double find_closest(int[] val, double average){
return (closest);
}
//Method to build the Display string and return the string
public static String display(int[] numbersArray, double count){
//Note that I do not display the results here, just build the string and return it.
return results;
}
}