import java.util.*;
import javax.swing.JOptionPane;
//create a class
public class prices {
//make the string input
public static void main(String[] args){
String Input;
double[] numbers; // An array for storing the input values.
int numCt; // The number of numbers saved in the array.
double num; // One of the numbers input by the user.
numbers = new double[4]; // Space for 100 ints.
numCt = 0; // No numbers have been saved yet.
Input = JOptionPane.showInputDialog(null, "Please enter a price.");
while (numCt < numbers.length) { // Get the numbers and put them in the array.
Input = JOptionPane.showInputDialog(null, "Please enter a price.");
num = Double.parseDouble(Input);
if (num <= 0)
break;
numbers[numCt] = num;
numCt++;
}
sumArray(numbers);
aveArray(numbers);
highPrices(numbers);
}
public static void sumArray(double arr[])
{
double sum = 0; // Start the total sum at 0.
for (int i=0; i<arr.length; i++) {
sum = sum + arr[i]; // Add the next element to the total
}
JOptionPane.showMessageDialog(null,"The sum of the prices is " + sum);
}
public static void aveArray(double rad[]){
double avg = 0;
double sum = 0; // Start the total sum at 0.
for (int i=0; i<rad.length; i++) {
sum = sum + rad[i]; // Add the next element to the total
avg = sum/rad.length;
}
JOptionPane.showMessageDialog(null,"The average of the prices is " + avg);
}
public static void highPrices(double rad[]){
// double avg; // Start the total sum at 0.
// for (int i=0; i<rad.length; i++) {
// sum = sum + rad[i]; // Add the next element to the total
// avg = sum/rad.length;
// }
JOptionPane.showMessageDialog(null,"ddd" + avg);
System.exit(0);
}
}
The high price array doesnt work --- i need it to recieve and average from the aveArray() and the Array numbers[] and retuen the numbers whose value is greater then the average to the main method.
Can anyone point me in the right direction?
Bookmarks