Question

In: Computer Science

Write program for the exercise 11(Sales Analysis) as explained at the end of the chapter. 11....

Write program for the exercise 11(Sales Analysis) as explained at the end of the chapter.

11. sales Analysis The file SalesData.txt, in this chapter’s source code folder, 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

Other Requirements:

The program file name must be: SalesAnalysisDemo.java

The data file that your program opens must be named as: SalesData.txt

Sample Data File attached here  SalesData.txt

1245.67,1490.07,1679.87,2371.46,1783.92,1461.99,2059.77
2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36
2513.45,1963.22,1568.35,1966.35,1893.25,1025.36,1128.36
1867.24,3124.20,1301.09,1489.27,1822.45,2111.89,1425.56
3296.54,9147.88,1801.45,0866.77,2001.21,0096.24,1156.83
2513.45,1963.22,1568.35,1966.35,1893.25,1025.36,1128.36

Test Case:

Weekly sales from week 1 is $12092.75
Average for week 1 is $1727.54
Weekly sales from week 2 is $27461.00
Average for week 2 is $3923.00
Weekly sales from week 3 is $12058.34
Average for week 3 is $1722.62
Weekly sales from week 4 is $13141.70
Average for week 4 is $1877.39
Weekly sales from week 5 is $18366.92
Average for week 5 is $2623.85
Weekly sales from week 6 is $12058.34
Average for week 6 is $1722.62
Total sale of all weeks = 95179.05
Average weekly sales = 15863.17
The week number with the highest amount of sales is: 2
The week number with the lowest amount of sales is: 3

Solutions

Expert Solution

Code:

====

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class SalesAnalysisDemo {
   public static void main(String[] args) throws FileNotFoundException {
       Scanner sc = new Scanner(new File("SalesData.txt"));
       String line = "";
       String [] week_array = null;
       double weekly_total = 0.0, final_total = 0.0, min_val = 0.0, max_val = 0.0;
       int week_num = 0, min_week = 0, max_week=0;
       while(sc.hasNextLine()) {
           line =sc.nextLine();
           week_array = line.split(",");
           for(String day_sale: week_array) {
               weekly_total = weekly_total+Double.parseDouble(day_sale);
               final_total = final_total+Double.parseDouble(day_sale);
           }
           System.out.println("Weekly sales from week " +(week_num+1)+" is $"+ Math.round(weekly_total*100)/100.0);
           System.out.println("Average for week" +(week_num+1)+" is $"+ Math.round((weekly_total/7.0)*100)/100.0);
           if(week_num==0) {
               min_val = weekly_total;
               max_val = weekly_total;
           }
           else {
               if(weekly_total<min_val) {
                   min_val = weekly_total;
                   min_week = week_num+1;
               }
               else if (weekly_total>max_val) {
                   max_val = weekly_total;
                   max_week = week_num+1;
               }
           }
           weekly_total=0;
           week_num++;
       }
      
       System.out.println("The week number with the highest amount of sales is: "+max_week);
       System.out.println("The week number with the lowest amount of sales is: "+min_week);
       sc.close();
   }
}

output:

=====


Related Solutions

Instructions Write a program to implement the algorithm that you designed in Exercise 19 of Chapter...
Instructions Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1. Your program should allow the user to buy as many items as the user desires. Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience. TEXT ONLY PLEASE (PLEASE NO PDF OR WRITING) C++ CODE Exercise 19 Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200...
Identify and write out the revenue recognition principle as explained in the chapter
Question: Refer to Apple’s financial statements in Appendix A to answer the following.1. Identify and write out the revenue recognition principle as explained in the chapter
Question 1 In this exercise, you are required to do a program analysis and write a...
Question 1 In this exercise, you are required to do a program analysis and write a program for a system that computes a speeding ticket cost. The charge is calculated as follows: P20 for every kilometre above the speed limit, plus P100 standard charge. E.g. If the speed limit is 60 km/hour and you are driving at 75 km/hour. The charge will be P400. If the speed is equal to or under the speed limit, then there is no charge....
C++ PROGRAM Programming Exercise 11 in Chapter 8explains how to add large integers using arrays. However,...
C++ PROGRAM Programming Exercise 11 in Chapter 8explains how to add large integers using arrays. However, in that exercise, the program could add only integers of, at most, 20 digits. This chapter explains how to work with dynamic integers. Design a class named largeIntegers such that an object of this class can store an integer of any number of digits. Add operations to add, subtract, multiply, and compare integers stored in two objects. Also add constructors to properly initialize objects...
Choose one of analysis methods that explained in Chapter 13. You have to do the following:...
Choose one of analysis methods that explained in Chapter 13. You have to do the following: - Explain the analysis method. (what the method means? and what is used for?) - Apply the analysis method to one of a real company's numbers. (you can take the number from the internet) - Explain the results. (what the results means) Note, you will not use any method that used by other student before you. This assignment will be available from Saturday 11...
Chapter 11 Exercise A4 Assume a company is going to make an investment of $450,000 in...
Chapter 11 Exercise A4 Assume a company is going to make an investment of $450,000 in a machine and the following are the cash flows that two different products would bring in years one through four. Option A, Product A Option B, Product B $190,000 $150,000 190,000 180,000 60,000 60,000 20,000 70,000 Which of the two options would you choose based on this payback method?
Modified from Chapter 07 Programming Exercise 5 Original Exercise: Rock, Paper, Scissors Modification Programming Exercise 11...
Modified from Chapter 07 Programming Exercise 5 Original Exercise: Rock, Paper, Scissors Modification Programming Exercise 11 in Chapter 6 asked you to design a program that plays the Rock, Paper, Scissors game. In the program, the user enters one of the three strings—"rock", "paper", or "scissors"—at the keyboard. Add input validation (with a case-insensitive comparison) to make sure the user enters one of those strings only. Modifications: Allow the user to input "r", "p", "s" or the full strings "Rock",...
Exercise 13-11 Profitability analysis LO P3 Simon Company’s year-end balance sheets follow. At December 31 2017...
Exercise 13-11 Profitability analysis LO P3 Simon Company’s year-end balance sheets follow. At December 31 2017 2016 2015 Assets Cash $ 31,000 $ 34,200 $ 37,500 Accounts receivable, net 89,100 62,700 51,600 Merchandise inventory 42,392 83,300 59,500 Prepaid expenses 11,004 9,960 4,192 Plant assets, net 411,504 274,840 217,208 Total assets $ 585,000 $ 465,000 $ 370,000 Liabilities and Equity Accounts payable $ 148,578 $ 76,227 $ 48,352 Long-term notes payable secured by mortgages on plant assets 108,880 105,880 83,405 Common...
At the end of Chapter 11, it mentioned "creative destruction." What is the main idea behind...
At the end of Chapter 11, it mentioned "creative destruction." What is the main idea behind that term? 1-The idea that a competitive marketplace will also be a creative one and that we should see new technologies and inventions as entreprenueurs try to "out do" each other. When downloading music became popular this pretty much eliminated the need for physical audio CDs. This was an example of creative destruction. 2-It is highly doubtful that a centrally planned communist economy (i.e....
Chapter 8 Programming exercise 6 "Days of each month" Original Exercise: Design a program that displays...
Chapter 8 Programming exercise 6 "Days of each month" Original Exercise: Design a program that displays the number of days in each month. The program’s output should be similar to this: January has 31 days. February has 28 days. March has 31 days. April has 30 days. May has 31 days. June has 30 days. July has 31 days. August has 31 days. September has 30 days. October has 31 days. November has 30 days. December has 31 days. The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT