Question: Open SalesData class program and fill in DETAILED comments following all empty //. 2. The Average method code has been deleted. You will need to

Open SalesData class program and fill in DETAILED comments following all empty //.

2. The Average method code has been deleted. You will need to write the code to calculate and return the average of the array. (Should start around line 51 of the SalesData file.

/** This class keeps the sales figures for a number of days in an array and provides methods for getting the total and average sales, and the highest and lowest amounts of sales. */ public class SalesData { private double[] sales; // The sales data /** The constructor copies the elements in an array to the sales array. @param s The array to copy. */ public SalesData(double[] s) { sales = new double[s.length]; for (int index = 0; index < s.length; index++) sales[index] = s[index]; // } /** getTotal method @return The total of the elements in the sales array. */ public double getTotal() // { double total = 0.0; for (int index = 0; index < sales.length; index++) total += sales[index]; // return total; // } /** getAverage method @return The average of the elements in the sales array. */ public double getAverage() { return getTotal() / sales.length; } /** getHighest method @return The highest value stored in the sales array. */ public double getHighest() { double highest = sales[0]; for (int index = 1; index < sales.length; index++) { if (sales[index] > highest) highest = sales[index]; } return highest; } /** getLowest method @returns The lowest value stored in the sales array. */ public double getLowest() { double lowest = sales[0]; for (int index = 1; index < sales.length; index++) { if (sales[index] < lowest) lowest = sales[index]; } return lowest; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres the SalesData class with detailed comments and the code for the getAverage method added This c... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!