I am trying to convert the import file String data type to Double and do the calculations, but some errors found. Any mistakes when making an assumption?
import java.io.*;
import java.util.*;
import java.lang.*;
public class Q4
{
public static void main (String [] args) throws IOException, NumberFormatException
{
File file = new File("SalesData.txt");
Scanner inputFile = new Scanner (file);
while (inputFile.hasNext())
{
String weekly_Sale = inputFile.nextLine();
String sale = weekly_Sale;
String list = sale;
Double value = Double.parseDouble(list);
Double[]data = value.split(",");
System.out.println(data);
}
inputFile.close();
}
}
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 daily sales for one week. The numbers are separated by a comma. The following 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 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