Here are the instructions:
Use a two-dimensional array to solve the following problem:
A company has four salespeople (1 to 4) who sell five different products (1 to 5). Once a day, each salesperson passes in a slip for each type of product sold. Each slip contains the following:
a) The salesperson number (1 to 4)
b) The product number
c) The total dollar value of the product (1 to 5) sold that day
Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all the slips for last month is available. Write an application that will read all this information for last month's sales and summarize the total sales by salesperson and by product. All totals should be stored in the two-dimensional array sales.
After processing all the information for a month (all the records in the data file), display the results in tabular format, with each column representing a particular salesperson and each row representing a particular product. Cross-total each row to get the total sales of each product for the month. Cross-total each column to get the total sales by salesperson for the month. Your tabular output should include these cross-totals to the right of the totaled rows and to the bottom of the totaled columns.
Then my code is: but doesn't seem to work.
TotalSales.java:47: array required, but int foundpublic class TotalSales { private String courseName; private int sales[]; public TotalSales (String name, int salesArray[] ) { courseName =name; sales = salesArray; } public void setCourseName (String name) { courseName =name; } public String getCourseName() { return courseName; } public void displayMessage() { System.out.printf("Total Sales Program\n%s!\n\n", getCourseName() ); } public void processSales () { outputSales(); System.out.printf("\n%s %d\n%s %d\n\n", "Highest Sales is", getMaximum(), "Lowest Sales is", getMinimum() ); outputBarChart(); } public int getMinimum() { int lowSales = sales[0][0]; for ( int totalSales[] : sale) { for (int sale :totalSales ) { if ( sale < lowSales) lowSales =sale; } } return lowSales; } public int getMaximum () { int highSale = sales[0][0]; for (int totalSales[] : sales) { for (int sale : totalSales) { if (sale > highSale) highSale = sale; } } return highSale; } public int getAvereage (int setofSales[]) { int total =0; for (int sale : setofSales ) total +=sale; return total / setofSales.length; } public void outputBarChart() { System.out.println ("Overall sale distribution:" ); int frequency[] = new int[11]; for (int totalSales[] : sales) { for (int sale : totalSales ) ++frequency [sale /10 ]; } for (int count =0; count <frequency.length; count++) { if (count==10) System.out.printf ( "%5d: ", 100); else System.out.printf ("%02d-%02d: ", count *10, count * 10 + 9); for (int stars =0; stars <frequency [ count ]; stars++) System.out.print ("*"); System.out.println(); } } public void outputSales() { System.out.println ("The sales are:\n"); System.out.print ( " " ); for (int test=0; test <sales[0].length; test++) System.out.printf ("Test %d ", test +1); System.out.println ("Avereage"); for (int work =0; work <sales.length; work++) { System.out.printf ("Worker %2d", work +1); for (int test : sales[ work] ) System.out.printf ("%8d", work); int average = getAverage(sales[ work]); System.out.printf ("9.2f\n", average); } } }
int lowSales = sales[0][0];
^
TotalSales.java:49: cannot find symbol
symbol : variable sale
location: class TotalSales
for ( int totalSales[] : sale)
^
TotalSales.java:63: array required, but int found
int highSale = sales[0][0];
^
TotalSales.java:65: incompatible types
found : int
required: int[]
for (int totalSales[] : sales)
^
TotalSales.java:92: incompatible types
found : int
required: int[]
for (int totalSales[] : sales)
^
TotalSales.java:114: int cannot be dereferenced
for (int test=0; test <sales[0].length; test++)
^
TotalSales.java:123: foreach not applicable to expression type
for (int test : sales[ work] )
^
TotalSales.java:126: cannot find symbol
symbol : method getAverage(int)
location: class TotalSales
int average = getAverage(sales[ work]);
^
8 errors
public class TotalSalesTest { public static void main ( String args[]) { int salesArray[][]= { {1, 1, 37}, {1, 2, 77}, {1, 3, 68}, {1, 4, 61} }; TotalSale myTotalSale = new TotalSale ( "Total Sales", salesArray); myTotalSale.display(); myTotalSale.processSales(); } }
TotalSalesTest.java:12: cannot find symbol
symbol : class TotalSale
location: class TotalSalesTest
TotalSale myTotalSale = new TotalSale (
^
TotalSalesTest.java:12: cannot find symbol
symbol : class TotalSale
location: class TotalSalesTest
TotalSale myTotalSale = new TotalSale (
^
2 errors
Please help me in advance.