Open SalesData class program and fill in DETAILED comments following all empty //. 2. The Average method
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 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; } }
Intermediate Accounting
ISBN: 978-1260481952
10th edition
Authors: J. David Spiceland, James Sepe, Mark Nelson, Wayne Thomas