![Quote](https://www.javaprogrammingforums.com/images/misc/quote_icon.png)
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.
![happy](http://www.javaprogrammingforums.com/yemotions/1.gif)
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;
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 ("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