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: 3641199 • 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.

Explanation / Answer

import java.util.Scanner; public class Prices { public static void main(String[] args) { double[] priceArray = new double[5]; // create a new array of type double Scanner scan = new Scanner(System.in); // instantiate a new scanner object to read input from console double temp = 0; // create a variable to hold the input from user for(int i = 0; i < 5; i++){ // start at 0, while less then 5, increment count System.out.println("Enter the #" + i + " Price: "); // print some message to user temp = scan.nextDouble(); // get the input from the user priceArray[i] = temp; // assignment of array at index of i to user input } System.out.println("The sum of all values in the array is: " + sumArray(priceArray)); // method call System.out.println("The average of all values in the array is: " + aveArray(priceArray)); // method call highPrices(priceArray); // method call } /** * Returns the sum of all values in the array * @param input - array of type double * @return double as sum */ public static double sumArray(double[] input) { double sum = 0; for(int i = 0; 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