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

SALES ANALYSIS JAVA The file SalesData.txt , the data below, contains the dollar

ID: 3696542 • Letter: S

Question

SALES ANALYSIS JAVA

The file SalesData.txt, the data below, contains the dollar amount of sales that a retail store made each day for a number of weeks. Each line in the file contains seven numbers, which are the numbers for one week. The numbers are separated by a comma. The following line is an example from the file:

Write a menu driven program named SalesAnalysis that has a menu with the following options below. When you read the data into memory, it is up to you how you store it. File locations should be chosen from a FileDialogBox or JFileChooser.

- Read the data from the file

- Calculate and print the average sales for each week (add up the seven days for a week and divide by seven)

- Store the values from the bullet point above into a text file, one per line so there should be one value in the file for each week

- Calculate and print the average daily sales for each week (add up each day of the week sets and divide by the number of weeks so you will have seven answers outputted – one for each day of the week.

- Exit

Explanation / Answer

public static void main(String[] args) throws IOException { Path salesDataPath = Paths .get("src/main/resources/com/levelup/java/exercises/beginner/SalesData.txt") .toAbsolutePath(); //read all lines into a list of strings List fileByLines = java.nio.file.Files .readAllLines(salesDataPath); //convert each string into a DoubleSummaryStatistics object List weeksSummary = new ArrayList(); for (String row : fileByLines) { // split on comma, map to double weeksSummary.add(Arrays.stream(row.split(",")) .mapToDouble(Double::valueOf).summaryStatistics()); } displayWeeklyStats(weeksSummary); displaySummaryResults(weeksSummary); } public static void displayWeeklyStats( List weeksSummary) { // for every week output the stats for (int x = 0; x p.getSum()).sum()); System.out.println("Average weekly sales: $" + weeksSummary.stream().mapToDouble(p -> p.getSum()).average() .getAsDouble()); System.out.println("The highest sales was $" + weeksSummary.stream().mapToDouble(p -> p.getSum()).max() .getAsDouble()); System.out.println("The lowest sales were made during " + weeksSummary.stream().mapToDouble(p -> p.getSum()).min() .getAsDouble()); }