The user should enter the input You can have the array defau
The user should enter the input.
You can have the array default to pre-set values for testing, but the final program should allow for user input.
We are having a cookie sales contest. The contest will run for 6 weeks with weekly winners in addition to the grand prize winner. Dollar volume is the goal. Each week the cookie salespeople will turn in one or more sales slips that will have the week number, price per box, number of boxes sold, and the salesperson\'s ID number. We want to create a program (CookieSales) that will hold all the data for the sale and determine the winners. For the data, you should use a two dimensional array with the following structure: Requirements: Create 2-dimensional array of the appropriate size Call a method to get the input into the array. In the method, prompt the user for the input (read the sales slips data). These sales slips are in random order with one slip per sale, there may be more than one slip per salesperson per week. Call method to calculate Column 7 - function to tally up sales, calculate and store total sales in column 7 Create a loop to locate the weekly winners - call the method with a given week #, then print the winner for each week. Print weekly winners - there may be multiple winners Locate grand prize winner and print the winner (may be multiple winners) input has the following parameters: SALENO - salesperson\'s ID (IDs range from 0 to 24) BOXES - number of boxes sold PRICE - price per box WEEK - week number (weeks are numbered 1 to 7) Goals Write a moderately difficult program that uses a two-dimensional array and methods. Get practice passing arrays to methods and declaring local variables inside those methods that will assist in accomplishing the desired task of the method. Calculating totals, finding max values within a 2D array Points to Think About You don\'t have to get the input method working in order to do the rest of the program. Remember that you can declare and instantiate an array using an initializer list. This is a good way to get around an input problem. Write methods that you can re-use. In other words, finding the maximum value (or values) in a column can be a single method that is called over and over again for each week - even the grand prize winner. You may need two separate methods for printing the winners - one to find the maximum value and then another for printing the winners. Class and File Naming Name your new class CookieSales and source file CookieSales. java. Grading Notes Your CookieSales. java file will not be graded without complete header and Honor Pledge documentation. Only submit the CookieSales. java source file into Blackboard. Method documentation must be present. Writing the methods as described is worth a portion of your grade. Sample Program Run (user input is underlined) Beginning cookie program Enter data from slips, enter -1 for id to stop Enter first id 0 Enter week number 1 Enter boxes sold 1 Enter price of each box 1 (Lots of other data entered here) Enter next id (-1 to quit) -1 (Here are contents of array, the rest are 0s) 1.0 4.0 0.0 0.0 0.0 0.0 5.0 1.5 0.0 0.0 0.0 0.0 0.0 1.5 25.0 4.0 0.0 0.0 0.0 0.0 29.0 0.0 0.0 9.0 0.0 0.0 0.0 9.0 0.0 0.0 0.0 16.0 0.0 0.0 16.0 10.0 3.0 0.0 0.0 25.0 0.0 38.0 2.0 0.0 0.0 0.0 0.0 36.0 38.0 Winners for week 1 with sales of $25.00 are: 2 Winners for week 2 with sales of $4.00 are: 0 2 Winners for week 3 with sales of $9.00 are: 3 Winners for week 4 with sales of $16.00 are: 4 Winners for week 5 with sales of $25.00 are: 5 Winners for week 6 with sales of $36.00 are: 6 Grand prize winners with sales of $38.00 are: 5 6 Thanks for using the cookie program!Solution
import java.util.*;
import java.lang.*;
import java.io.*;
class CookieSales {
double[][] data;
CookieSales() {
data = new double[24][7];
for (double[] row: data)
Arrays.fill(row, 0.0);
}
public void getData() {
int id,week_number,boxes_sold;
double price_of_box;
Scanner r = new Scanner(System.in);
System.out.println(\"Enter data from slips, enter -1 for id to stop\");
System.out.println(\"Enter first id \");
id = r.nextInt();
while(id != -1) {
System.out.println(\"Enter week number \");
week_number = r.nextInt();
System.out.println(\"Enter boxes sold \");
boxes_sold = r.nextInt();
System.out.println(\"Enter price of each box \");
price_of_box = r.nextDouble();
this.data[id][week_number-1] = (price_of_box * boxes_sold); //Add data to 2d array
System.out.println(\"Enter next id (-1 to quit)\");
id = r.nextInt();
}
}
public void calculateSum() {
for(int i=0;i<24;i++) {
double sum = 0.0;
for(int j=0;j<6;j++){
sum += this.data[i][j];
}
this.data[i][6] = sum;
}
}
public void locateWeeklyWinners() {
for(int i=0;i<5;i++){
double winner = 0.0;
int[] winnerIndex = new int[24];
Arrays.fill(winnerIndex,0);
for(int j=0;j<24;j++){
if(winner < this.data[j][i]){
winner = this.data[j][i];
Arrays.fill(winnerIndex,0);
winnerIndex[j] = 1;
}
else if(winner == this.data[j][i]) {
winnerIndex[j] = 1;
}
}
System.out.println(\"Winners for week \" + (i+1) + \" with sales of are: \");
for(int k=0;k<24;k++){
if(winnerIndex[k] == 1) {
System.out.println(k + \" \");
}
}
System.out.println(\"\ \");
}
}
}

