i basically have to write code which takes in 5 prices from insurance companies A-E from the user and outputs the average price, and cheapest price with the companies id which would be A,B,C,D,E
here is my code so far, I got it to list the average but cant seem to figure out how to get the cheapest price, or how to make it have the companies id out-putted.
public class InternetCompare
{
public static void main(String[] args)
{
int[] prices = new int[5];
// Read in ages
int i = 0;
String s = JOptionPane.showInputDialog(
"enter a price, -1 to stop:");
int n = Integer.parseInt(s);
while ((i <= prices.length - 1) && (n != -1))
{
prices[i] = n;
s = JOptionPane.showInputDialog(
"enter a price, -1 to stop:");
n = Integer.parseInt(s);
i++;
}
int nextFree = i;
// nextFree is index of next free element in array
// compute average age
int total = 0;
for (int j = 0; j < nextFree; j++)
{
total += prices[j];
}
double ave = total / (double) nextFree;
JOptionPane.showMessageDialog(null, "Average price is " + ave);
}
}