Hi all! I'm new to Daniweb and to programming. I'm learning Java with the book Java how to program 7th edition. I'm stuck at an exercise where I'm supposed to create three objects that each inputs an hourly rate, number of hours, and a name for the employee given by a user. If the number of hours exceeds 40 it's a 50% increase in the hourly rate. Then output it all.

The code runs fine until line 25 in "GrossPayTest". Error I get:

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '2' +
at GrossPayTest.main(GrossPayTest.java:25)

I have looked at line 25 (GrossPayTest) for some time now but don't get it. Please help.

import java.util.Scanner;

public class GrossPay {

private double rate;
private double hours;
private double salary;
private String name;

public GrossPay(double hour, double pay, String Name){
	hours = hour;
	rate = pay;
	name = Name;
public String getName()
	return name;

public double getSalary()
	return salary;

public double getHours()
	return hours;

public double getRate(){
	return rate;

public void setNrHour()
	Scanner in = new Scanner(System.in);
	System.out.print("Enter number of hours worked: ");
	hours = in.nextDouble();

public void setRate()
	Scanner in = new Scanner(System.in);
	System.out.print("Enter hourly rate: ");
	rate = in.nextDouble();

public void setName()
	Scanner in = new Scanner(System.in);
	System.out.println("Set name: ");
	name = in.nextLine();

//If above 40 hours, each hour + 50%.
public double generateIncome(){
	double h;
	double increaseAmount;
	if (hours > 40){
    salary = 40 * rate;
    h = hours - 40;
    increaseAmount = h * rate * 1.5;
    salary += increaseAmount;
		salary = hours * rate;
	return salary;		
public class GrossPayTest {

	public static void main (String args []){
		GrossPay Employee1 = new GrossPay (0,0,"Nilsen");
		GrossPay Employee2 = new GrossPay (0,0,"Jonsen");
		GrossPay Employee3 = new GrossPay (0,0,"Evensen");
		System.out.printf ("Name of employee: %s has worked %.2f hours" +
				" and earned %2.f this week", Employee1.getName(),    Employee1.getRate(), Employee1.getSalary());
7 Years
Discussion Span
Last Post by jon.kiparsky

Your string formatting is a little off. For printf-style formatting, you want something like %2.2f - two digits separated by a period.


You're welcome.
I suggest that you make your next thread title a little more descriptive, so someone scanning the list of threads will know what sort of problem you're dealing with. If you'd posted this during the workday, I probably wouldn't have even looked at it, but if it'd had a title like "Unknown Format Conversion Exception" I would have been able to guess straight off what the problem was.
To paraphrase Eric Raymond, if you're asking people to help you out, make it easy for them by telling them quickly and clearly what you're having trouble with.
(read his essay on "How To Ask Questions..." - first thing that comes up with his name and those words in google, it's a good one if you're trying to learn something)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.