Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a java program that will prompt the user for a list of 5 prices. Once the

ID: 3625000 • Letter: W

Question

Write a java program that will prompt the user for a list of 5 prices. Once the user has entered all values, your program should compute and display the following:
The sum of all the prices
The average of the prices
All prices that are higher than the calculated average


When you are finished writing these methods, create a main method that will prompt the user for the 5 prices.

Please enter a value: 1.23
2.34
3.45
4.56
5.00

The sum of these values is $16.58
The average of these values is: $3.32
The values higher than the average are: $3.45 $4.56 $5.67

I would appreciate any help. I need to turn it in within the next 48 hours so if you can, please help! :)
thank you

Explanation / Answer

public static void main(String[] args)
{
double[] prices = new double[5];

Scanner kb = new Scanner(System.in);

System.out.print("Please enter a value: ");

for(int i = 0; i < prices.length; i++)
prices[i] = kb.nextInt();

System.out.printf("The sum of these values is $%.2f ", sum(prices));
System.out.printf("The average of these values is $%.2f ", average(prices));
System.out.println("The values higher than the average are: "+greaterThanAverage(prices));
}

public static double sum(double[] prices)
{
double output = 0;

for(double i : prices)
output += i;
return output;
}

public static double average(double[] prices)
{
return sum(prices)/prices.length;
}

public static String greaterThanAvg(double[] prices)
{
double avg = average(prices);
String output = "";

for(double i : prices)
if(i > avg)
output += i+" ";
return output;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote