Hello, I really need help with my payroll program. I just need to input the name, wage, hours, and then get an output with the results. The output needs to show employee name, rate, wage, and total pay. here is what I have written so far. Please help! I am getting some format.double error

import java.util.Scanner;

public class Payroll1
{
    //bla bla
    public static void main (String args[] )
    {
        //main execution
        Scanner input = new Scanner( System.in );

        String empName;
        double wage;
        double hours;
        double pay;

        System.out.print( "What is the name of the employee?:" );
        empName = input.nextLine();

        System.out.print( "What is the hourly rate?");
        wage = input.nextDouble();

        System.out.print( "How many hours?");
        hours = input.nextDouble();

        pay = hours * wage;

        System.out.print( empName );
        System.out.printf( "The total pay is %d\n",pay);


    }
}

I am getting some format.double error

Please copy here the full text of the error message.

System.out.printf( "The total pay is %d\n",pay);

Read the API doc for the Formatter class to see how to write the formats for different data types.

OK i figured it out to be that the last line contains %f\n, because it uses the float data type. Here is my new program:

import java.util.Scanner;

public class Payroll1
{
    //bla bla
    public static void main (String args[] )
    {
        //main execution
        Scanner input = new Scanner( System.in );

        String empName; 
        float wage;
        float hours;
        float pay;

        System.out.print( "What is the name of the employee?:" );
        empName = input.nextLine();

        System.out.print( "What is the hourly rate?");
        wage = input.nextFloat();

        System.out.print( "How many hours?");
        hours = input.nextFloat();

        pay = hours * wage;

        System.out.print( empName);
        System.out.printf( "Hourly Rate:", wage);
        System.out.printf( "The total pay is %f\n",pay);

I now just need to figure how how to display the proper format, and I don't know how to output the name that I put in. Here is what I get when I put in my name with hourly rate=8, and hours=5

What is the employee nameChris
What is the hourly rate?8
How many hours?5
Hourly Rate: The total pay is 40.00000

I need it to look nice like this

Name:
Hourly Rate:
Hours:
Total Pay;

';' expected

Read the error message. It is telling you what is wrong.

To get that output use the following:

System.out.println("Name:\nHourly Rate:\nHours:\nTotal Pay");

ok, so here is the new program, but now all of the fields are blank when it outputs to the screen

import java.util.Scanner;

public class Payroll1
{
    //bla bla
    public static void main (String args[] )
    {
        //main execution
        Scanner input = new Scanner( System.in );

        String empName;
        float wage;
        float hours;
        float pay;

        System.out.print( "What is the employee name" );
        empName = input.nextLine();

        System.out.print( "What is the hourly rate?");
        wage = input.nextFloat();

        System.out.print( "How many hours?");
        hours = input.nextFloat();

        pay = hours * wage;


        System.out.println("Employee Name:\nHourly Rate:\nHours:\nPay");


    }

So it just has

Employee Name:
ect

Do I have to use the 'return empName;' statement somewhere so that I can display it at the end?

I need it to look nice like this

Name:
Hourly Rate:
Hours:
Total Pay;

Isn't that what you asked for???

Can you explain what it is you want to see?

Isn't that what you asked for???

Can you explain what it is you want to see?

Sorry I guess i was not specific

I need it to say something akin to

Employee Name: Chris
Hourly Rate: 7
Hours: 40
Total Pay: 280 (USD format)

I'm a lot like a computer. When you say I want it like this, I assumed that's what you meant.
To build your output, use String concatenation in the println():
println("label here:" + value_variable);

I'm a lot like a computer. When you say I want it like this, I assumed that's what you meant.
To build your output, use String concatenation in the println():

println("label here:" + value_variable);

Thank You! I've almost got it! here is my new code:

import java.util.Scanner;

public class Payroll1
{
    //bla bla
    public static void main (String args[] )
    {
        //main execution
        Scanner input = new Scanner( System.in );

        String empName;
        float wage;
        float hours;
        float pay;

        System.out.print( "What is the employee's name?:" );
        empName = input.nextLine();

        System.out.print( "What is the hourly rate?");
        wage = input.nextFloat();

        System.out.print( "How many hours?");
        hours = input.nextFloat();

        pay = hours * wage;

        System.out.println("Employee:" + empName);
        System.out.println("Hourly rate:" + wage);
        System.out.println("Total Hours worked:" + hours);
        System.out.println("Total Pay:" + pay);



    }

}

Isn't there also a way to output the last part with printf? Also, how to I convert the values into a USD notation? Honestly, my class study book is not very helpful.

I figured it out... heres what i put with printf

System.out.println("Employee:" + empName);
System.out.printf("Hourly rate: $%.2f\n", wage);
System.out.println("Total Hours worked:" + hours);
System.out.printf("Total Pay: $%.2f\n", pay);

Deleted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.