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

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

ID: 3624305 • Letter: W

Question

Write a 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

To better solve this problem, break your code out into the following methods:

? sumArray – this method should receive an array and return the sum of all elements in the array. NOTE: this method produces no output.
? aveArray – this method should receive an array and return the average of all elements in the array. NOTE: this method produces no output.
? highPrices – this method should receive an array and an average. It should then print out all elements in the array whose values are greater than the average.
When you are finished writing these methods, create a main method that will prompt the user for the 5 prices and then call the appropriate methods.

Be sure your program demonstrates good programming style (appropriate comments, identifier names, indenting, etc).
Although your output is not required to look this way, it might look something like:

Please enter a value: 1.23
Please enter a value: 2.34
Please enter a value: 3.45
Please enter a value: 4.56
Please enter a value: 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

Explanation / Answer

import java.io.*;
import java.util.Scanner;

class test{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        double[] a = new double[5];
        double sum = 0,avg;
     for(int i=0; i<5; i++)
     {
         System.out.println("Please enter a value: ");
         a[i] = in.nextDouble();
       
     }
       
System.out.println("The sum of these values is $" + sumArray(a));
System.out.println("The average of these values is "+ avgArray(a));
highPrices(a,avgArray(a));

}
    public static double sumArray(double[] a)
    {
        double s=0;
     for(int i=0; i<5; i++)
     {
         s = s+ a[i];
     }
        return s;
    }
public static double avgArray(double[] a)
    {
        double s=0;
     for(int i=0; i<5; i++)
     {
         s = s+ a[i];
     }
        return s/5;
    }
public static void highPrices(double[] a,double p)
{
System.out.println("The values higher than the average are:");

    for(int i=0; i<5; i++)
{
    if(a[i]>p)
        System.out.println("$ " + a[i]);
}

}
}

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