Posted by: Slackdemic October 30, 2006
Java program doesn't compile??
Login in to Rate this Post:     0       ?        
import java.util.Scanner; public class Lab09 { Scanner input = new Scanner( System.in ); 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: "); int product = input.next(); 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 ]; for ( int column = 0; column < 4; column++ ) salesPersonTotal[ column ][ row ] = 0; System.out.printf( "%7s%14s%14s%14s%14s%10s\n", "Product", "Salesperson1","Salesperson2","Salesperson3", "Salesperson 4", "Total" ); for ( int row = 0; row < 5; row++ ) { double productTotal = 0.0; System.out.printf( "%7d", (row + 1) ); for ( int coulumn = 0; column < 4; column++ ) { System.out.printf( " %14.2f", sales[ column ][row] ); productTotal += sales[ column ][ row ]; } System.out.printf( "%7s", "Total"); for ( int column = 0; column < 4; column++ ) System.out.printf( "%14.2f", salesPersonTotal[ column ] ); System.out.println(); } } .................. public class lab09Test { public static void main (String args[] ) { Lab09 application = new Lab09(); application.calculateSales(); } }
Read Full Discussion Thread for this article