I corrected several mistakes and now it runs, but still not giving desired output:
import java.util.Scanner;
public class Lab09
{
public void calculateSales()
{
Scanner input = new Scanner( System.in );
/*[][] missing after the variable sales */
double sales[][] = new double[ 5 ][ 4 ];
System.out.print( "Enter sales person number (-1 to end ): ");
int person = input.nextInt();
while( person != -1 )
{
System.out.print( "Enter product number: ");
/*Compilation error: it should be input.nextInt(), not input.next()*/
int product = input.nextInt();
System.out.print( "Enter sales amount: ");
double amount = input.nextDouble();
if ( person < 1 && person > 5 && product >= 1 && product < 6 && amount >= 0)
sales[ product-1][person-1] += amount;
else
System.out.println("Invalid input!" );
System.out.print( "Enter sales person number (-1 to end): ");
person = input.nextInt();
}
double salesPersonTotal[][] = new double[ 4 ][ 5 ];
/* for statement missing for row */
for ( int row = 0; row < 5; row++ )
{
for ( int column = 0; column < 4; column++ )
{
salesPersonTotal[ column ][ row ] = 0;
}
}
System.out.printf( "%7s%14s%14s%14s%14s%10s\n", "Product", "Salesperson 1","Salesperson 2","Salesperson 3", "Salesperson 4", "Total" );
for ( int row = 0; row < 5; row++ )
{
double productTotal = 0.0;
System.out.printf( "%7d", (row + 1) );
for ( int column = 0; column < 4; column++ )
{
System.out.printf( " %14.2f", sales[ column ][row] );
productTotal += sales[ column ][ row ];
salesPersonTotal[ column ][ row ] += sales[ column ][row ];
}
System.out.printf( "%7s", "Total" );
}
System.out.printf( "%7s", "Total");
for ( int column = 0; column < 4; column++ )
System.out.printf( "%14.2f", salesPersonTotal[ column ] );
System.out.println();
}
}