It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Help please, due in 1 hour. Does not compile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help please, due in 1 hour. Does not compile" Watch "Help please, due in 1 hour. Does not compile" New topic

Help please, due in 1 hour. Does not compile

Shawn Lorne

Joined: Jun 23, 2012
Posts: 1

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.

Winston Gutkowski

Joined: Mar 17, 2011
Posts: 7545

Shawn Lorne wrote:Hi all,
Kinda short on time. Error message:

Well, looks like your time has expired, so there's not much point in replying; but for future reference:
1. UseCodeTags (←click).
2. EaseUp.
3. TellTheDetails.
In fact, a good read of the HowToAskQuestionsOnJavaRanch page would probably be in order.

And next time: Don't leave it so late.


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Rob Spoor

Joined: Oct 27, 2005
Posts: 19653

First of all, don't use \n, use %n. That will result in \n on Linux and \r\n on Windows.

Shawn Lorne wrote: System.out.printf("8%d%",(row +1) );
System.out.printf("8%s", "Total");
System.out.printf("14.2%f", salesPersonTotal[column]);

Check out the % signs in these three statements. The second and third ones will work but not as intended (the 8 and 14.2 will be printed as-is, not be used for formatting), the first one is plain wrong. If you need to include a literal % sign you must duplicate it: %%.

How To Ask Questions How To Answer Questions
subject: Help please, due in 1 hour. Does not compile
Similar Threads
Multiplication Table
specifier format?
Program Problem
Program Output not working
cant get output right