Shawn Lorne

+ Follow
since Jun 23, 2012
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Shawn Lorne

Hi all,
Kinda short on time. Error message:

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '%'
at java.util.Formatter.checkText(
at java.util.Formatter.parse(
at java.util.Formatter.format(
at Sales2.main(
Java Result: 1

Here is the code!

// Exercise 7.20 Solution:
// Program totals sales for salespeople and products.
import java.util.Scanner;

public class Sales2
public static void main( String[] args )
Scanner input = new Scanner( );
// sales array holds data on number of each product sold
// by each salesperson
double[][] sales = new double[ 5 ][ 4 ]; // 5 salespeople, 4 products each person

System.out.print( "Enter salesperson number (-1 to end): " );

int person = input.nextInt(); // the salesperson index

while ( person != -1 )
// To do
// prompt to enter product number and save it as an integer
System.out.print("Please enter the product number: ");
int product = input.nextInt();
// promp to enter sales amont and save it as double
System.out.print("Please enter the sales amount: ");
double salesAmount = input.nextDouble();
// error-check the input number for the array boundary
//error check input
if (person >= 1 && person < 5 && product >=1 && product < 6 &&
salesAmount >= 0)
sales[product -1][person -1] =+ salesAmount;
System.out.println("Invalid Input!");

System.out.print("Enter sales person number(-1 to end):");
person = input.nextInt();
}//end while

//salesperson totals
double salesPersonTotal[] = new double[4];

//display data table
for (int column = 0; column < 4; column ++)
salesPersonTotal[column] = 0;

"Product", "Salesperson 1", "Salesperson 2","Salesperson 3",
"Salesperson 4", "Total");

//Printing a person's sales of a product
for (int row = 0; row < 5; row ++)
double productTotal = 0.0;
System.out.printf("8%d%",(row +1) );

for ( int column = 0; column < 4; column ++)
System.out.printf("%14.2f", sales[row][column]);
productTotal += sales[row][column];
salesPersonTotal[column] += sales[row][column];
} //end for loop

System.out.printf("8%s", "Total");

for (int column = 0; column < 4; column ++)
System.out.printf("14.2%f", salesPersonTotal[column]);


}// end calculations

} // end main

What am I missing??? The table does not want to show.

Edit: Forgot problem spec

7.20 (Total Sales) 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
b) The product number
c) The total dollar value of that product sold that day

Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all of 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 last month, 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 last month. Cross-total each column to get the total sales by salesperson for last month. Your tabular output should include these cross-totals to the right of the totaled rows and to the bottom of the totaled columns.

See attached program template and output sample.

11 years ago