Quote:

import javax.swing.*;

public class fivePrices

{

public static void main(String[] args)

{//variable declaration section

String[] items = {"Apples", "Bananas", "Nectarines", "Oranges", "Plums"};//this line fills the array items with the 5 items

double[] price = new double[5];//declares a new price array that contains 5 doubles

for (int i = 0; i < items.length; i++) //initialize counter to fill array

{

price[i] = Double.parseDouble(JOptionPane.showInputDialog(("E nter Price for " + items[i])));//gets user input for 5 prices

}

double s = sumArray(price);

double a = aveArray(price);

JOptionPane.showMessageDialog(null, "The total cost of these items is: $" + s);

JOptionPane.showMessageDialog(null, "The average cost of these items is: $" + a);

JOptionPane.showMessageDialog(null, "The prices above average are: ");

higherAve(price, a);

}

//two methods to figure sum and average

public static double sumArray(double[] array)

{//method for sum

double sum = 0.00;

for(int s = 0; s < array.length; s++)

sum += array[s];

return sum;

}

public static double aveArray(double[] array)

{

double average =0.00;

double sum = sumArray(array);

return average = (sum / array.length);

}

public static void higherAve(double[] price, double a)

{//method to determine prices that are above the average price as wel as returns output

String result = "";

for (int i = 0; i < price.length; i++)

{

if(price[i] > a)

{

result += "$"+price[i]+"\n";

}

}

JOptionPane.showMessageDialog(null, result);

}

}//end class