Question: Given the following Java program ShortCoding.java, follow the instructions in steps 1-8 to add source code to complete the program. The questions are within the

Given the following Java program ShortCoding.java, follow the instructions in steps 1-8 to add source code to complete the program. The questions are within the code

//ShortCoding.java import java.io.*; import java.util.Arrays; import java.util.Scanner;

public class ShortCoding {

public static void main(String[] args) throws FileNotFoundException { final int numStores = 3; final int numSeasons= 4; //declare a store variable to reference an array of store data which contains three stores' seasonal sales int[][] storeData = new int[numStores][numSeasons]; //declare a storeNames variable to reference an array of store names with contains the names of the three stores String[] storeNames = new String[numStores]; String filename = "salesdata.txt"; //[2pts] step-1: Based on the definition of the readInData method to add a method call statement to call readInData //method to read in store names and their seasonal sales from external text file named "salesdata.txt" //call calStoreTotal method to calculate total seasonal sales for each store int[] storeTotal= calStoreTotal(storeData); //call calSeasonalTotal method to calculate total sales from all stores for each season int[] seasonalTotal= calSeasonalTotal(storeData); //[3pts] step-2: Add java code to print out the store names, total seasonal sales for each store, and total sales from all stores for each season //(i.e., print out data in storeNames, totalStoreSales, and totalSeasonalSales arrays)

} //end of main // Complete the definition of readInData method public static void readInData(String fileName, String[] storeNames, int[][] storeData) { try { Scanner fileReader = new Scanner(new File(fileName)); int i=0; while (fileReader.hasNext() && i< storeNames.length) { //read in each line from the file String dataRecord = fileReader.nextLine(); //[2pts] Step-3: Add a java statement to split the String dataRecord by using comma , //[2pts] Step-4: Complete the java statement to assign first token in the dataTokens array to storeNames array storeNames[i] = ; //[2pts] Step-5: Add java statements in the following for loop to convert the rest of the data in dataTokens array to integers, // and assign them to storeData array for (int m=1; m < dataTokens.length; ++m) { } i++; } // end of the while loop fileReader.close(); }//end of the try block //[3pts] Step-6: Add a catch block here to handle FileNotFoundException so that if FileNotFoundException occurs, //print out an error message in console says: "File not found!! Try again later." and exit the program by using System.exit(1);

}//end of readInData method // Define calStoreTotal method public static int[] calStoreTotal (int[][] storeData){ int numStore = storeData.length; int numSeason = storeData[0].length; int[] storeTotal = new int[numStore]; //[4pts] Step-7: Add java code below to calculate total seasonal sales for each store (i.e., row average) by using the data stored in the storeData array //and assign total seasonal sales for each store to storeTotal array return storeTotal; } //end of calAverage method

// Define calSeasonalTotal method public static int[] calSeasonalTotal (int[][] storeData){ int numStore = storeData.length; int numSeason = storeData[0].length; int[] seasonalTotal = new int[numSeason]; //[4pts] Step-8: Add java code below to calculate total sales from all stores for each season (i.e., column average) by using the data stored in the storeData array //and assign total store sales for each season to seasonalTotal array return seasonalTotal; } //end of calSeasonalTotal method

} //end of class

/*************************End of the program**********************************************/

The salesdata.txt file is as follows:

Madison,78,69,70,72

Janesville,86,78,91,89

Whitewater,56,89,74,70

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!