This program should be written in Java Language. Sales Analysis The file SalesDa
ID: 3585303 • Letter: T
Question
This program should be written in Java Language. Sales Analysis The file SalesData.txt 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 sales numbers for one week. The numbers are separated by a comma. The following line is an example from the file: 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36 Write a program that opens the file and processes its contents. The program should display the following: The total sales for each week The average daily sales for each week The total sales for all of the weeks The average weekly sales The week number that had the highest amount of sales The week number that had the lowest amount of sales
Explanation / Answer
weeksalesData.txt
2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36
1233.45,4556.77,7890.93,2343.43,6543.67,5678.95,3245.76
7612.45,7899.66,1111.11,2222.22,3333.33,4444.44,5555.55
9999.99,8888.88,7777.66,5555.55,4444.33,1231.54,6788.76
8767.99,5434.43,1267.76,6548.88,7656.78,9878.12,5467.89
1767.89,3456.76,2333.45,6789.99,3434.56,7888.76,3456.87
5478.88,7654.32,5678.98,9087.78,4512.22,6790.09,5434.45
________________________
AnalyzeSalesData.java
package org.students;
import java.io.File;
import java.util.Scanner;
public class AnalyzeSalesData {
public static void main(String[] args) {
//Declaring variables
Scanner sc = null;
String line;
double weekTotal = 0.0;
double totalSalesAllWeeks = 0.0;
int minIndex = 0, maxIndex = 0;
double weekMIn, weekMax;
weekMIn = Double.MAX_VALUE;
weekMax = Double.MIN_VALUE;
//Creating an 2-D array of which stores the weekly sales
double Sales[][] = new double[7][7];
int i = 0, j = 0;
try {
//Opening the file
sc = new Scanner(new File("weeksalesData.txt"));
while (sc.hasNext()) {
line = sc.nextLine();
String arr[] = line.split(",");
for (int k = 0; k < arr.length; k++) {
Sales[i][j] = Double.parseDouble(arr[k]);
j++;
}
i++;
j = 0;
}
//Displaying the report
System.out.println(" Day#1 Day#2 Day#3 Day#4 Day#5 Day#6 Day#7 Week-Total Week-Avg");
for (i = 0; i < 7; i++) {
System.out.print("Week#" + (i + 1) + ":");
for (j = 0; j < 7; j++) {
System.out.print(Sales[i][j] + " ");
//calculating the weekly total
weekTotal += Sales[i][j];
//calculating the all weeks total
totalSalesAllWeeks += Sales[i][j];
}
//Displaying weekly total
System.out.printf("%.2f ", weekTotal);
//Displaying weekly average
System.out.printf("%.2f", weekTotal / 7);
//finding in which week min total sales
if (weekMIn > weekTotal) {
weekMIn = weekTotal;
minIndex = i;
}
//finding in which week max total sales
if (weekMax < weekTotal) {
weekMax = weekTotal;
maxIndex = i;
}
System.out.println();
weekTotal = 0.0;
}
System.out.print("---------------------------------------------------");
System.out.println("---------------------------------------------------");
double dayTot;
System.out.print("dayAvg:");
for (i = 0; i < 7; i++) {
dayTot = 0.0;
for (j = 0; j < 7; j++) {
dayTot += Sales[j][i];
}
System.out.printf("%.2f ", dayTot / 7);
}
//Displaying the output
System.out.printf(" Total Slaes for all weeks:$ %.2f ", totalSalesAllWeeks);
System.out.println("Week number that has highest amount of sales is " + (maxIndex + 1));
System.out.println("Week number that has highest amount of sales is " + (minIndex + 1));
} catch (Exception e) {
System.out.println("** File No found **");
}
}
}
_________________________
Output:
Day#1 Day#2 Day#3 Day#4 Day#5 Day#6 Day#7 Week-Total Week-Avg
Week#1:2541.36 2965.88 1965.32 1845.23 7021.11 9652.74 1469.36 27461.00 3923.00
Week#2:1233.45 4556.77 7890.93 2343.43 6543.67 5678.95 3245.76 31492.96 4498.99
Week#3:7612.45 7899.66 1111.11 2222.22 3333.33 4444.44 5555.55 32178.76 4596.97
Week#4:9999.99 8888.88 7777.66 5555.55 4444.33 1231.54 6788.76 44686.71 6383.82
Week#5:8767.99 5434.43 1267.76 6548.88 7656.78 9878.12 5467.89 45021.85 6431.69
Week#6:1767.89 3456.76 2333.45 6789.99 3434.56 7888.76 3456.87 29128.28 4161.18
Week#7:5478.88 7654.32 5678.98 9087.78 4512.22 6790.09 5434.45 44636.72 6376.67
------------------------------------------------------------------------------------------------------
dayAvg:5343.14 5836.67 4003.60 4913.30 5278.00 6509.23 4488.38
Total Slaes for all weeks:$ 254606.28
Week number that has highest amount of sales is 5
Week number that has highest amount of sales is 1
_____________Could you rate me well.Plz .Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.