package sumproductapp;
import javax.swing.JOptionPane;
/**
*
* @author SETH
*/
public class SumProductApp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// declare variables
final int SIZE = 5;
int [] numbers = new int[SIZE];
String strNum;
int num,sum = 0, product = 1;
//prompt the user to enter a number
strNum = JOptionPane.showInputDialog(null, "Please enter number " , "Input", JOptionPane.PLAIN_MESSAGE);
//convert the string number to a numeric value
num = Integer.parseInt(strNum);
//populate the array --> fill the array with numbers
for(int i = 1; i < SIZE; i++){
if(i==0){
JOptionPane.showMessageDialog(null,"Invalid input data", "Wrong input", JOptionPane.ERROR_MESSAGE);
JOptionPane.showInputDialog(null,"Please re-enter a number " ,"Input", JOptionPane.PLAIN_MESSAGE);
//store the number at an index/position of the array
numbers[i] = num;
while(num>0){
}
}
}
//determine the sum of the elements
for(int i = 1; i < SIZE; i++){
//get a number at an index
num = numbers[i];
//determine sum
sum = sum + num;
}
//determine the product
for(int i = 1; i < SIZE; i++ ){
//get a number at an index
num = numbers[i];
//determine the product
product = product * num;
}
//display the sum and product
JOptionPane.showMessageDialog(null, "The sum is " + sum + "\n" +
"The product is " + product,
"Outcome", JOptionPane.INFORMATION_MESSAGE);
}
}