# Total Sales Error

• March 14th, 2012, 03:43 PM
KRUKUSA
Total Sales Error
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.

Code java:

```public 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); } } }```
TotalSales.java:47: array required, but int found
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

Code java:

```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

• March 17th, 2012, 07:59 PM
KRUKUSA
Re: Total Sales Error
• March 18th, 2012, 07:24 PM
KRUKUSA
Re: Total Sales Error
bump anyone?
• March 19th, 2012, 06:34 AM
andreas90
Re: Total Sales Error
Hello KRUKUSA!
I think your compiler tells you exactly what are your errors. Remember that a 1d int array (sales[]) differs from a 2d int array(sales[][]). You should take a look at the Java API about Variables. And something else about your TotalSalesTest class, TotalSale is different from TotalSales. :)
Hope it helps.
• March 19th, 2012, 08:20 PM
KRUKUSA
Re: Total Sales Error
Quote:

Originally Posted by andreas90
Hello KRUKUSA!
I think your compiler tells you exactly what are your errors. Remember that a 1d int array (sales[]) differs from a 2d int array(sales[][]). You should take a look at the Java API about Variables. And something else about your TotalSalesTest class, TotalSale is different from TotalSales. :)
Hope it helps.

Thanks for the help i fixed the program and got it to display but it isn't working lik

public

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 display()
{
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[] : sales)
{

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 getAverage (int setofSales[])
{
int total =0;

for (int sale : setofSales )
total +=sale;

}

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 ("Average");

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);

double average = getAverage(sales[work]);
System.out.printf ("%9.2f\n", average);
}
}
}

public

class TotalSalesTest
{

public static void main ( String args[])
{

int salesArray[][]= { {1, 1, 37},
{1, 2, 77},
{1, 3, 68},
{1, 4, 61} };

TotalSales myTotalSales = new TotalSales (
"Total Sales", salesArray);
myTotalSales.display();
myTotalSales.processSales();
}
}

It displays something like this.
how come all the values aren't going into the first worker?

Test 1 Test 2 Test 3 Average
Worker 1 0 0 0 13.00
Worker 2 1 1 1 26.00
Worker 3 2 2 2 24.00
Worker 4 3 3 3 22.00