Results 1 to 4 of 4
  1. #1
    KiskaBaker is offline Member
    Join Date
    Aug 2009
    Location
    Georgia
    Posts
    2
    Rep Power
    0

    Question Payroll Project 1 Troubles

    I am currenly trying to get a little ahead in class and have reviewed the materials for such and started on the Payroll project. I have went over and over these problem and cannot seem to find where my errors are.


    PHP Code:
    package payroll1;
    
    /**
     *
     * @author Kiska
     */
    import java.util.Scanner;  //program uses Scanner
    public class Payroll1 {
    
        /**
         * @param args the command line arguments
         */
        @SuppressWarnings("empty-statement")
        public static void main(String[] args) {
            System.out.println("Welcome to Payroll Program Part 1");  //welcome message
            Scanner input = new Scanner (System.in);   //creates Scanner for input
    
            boolean enterMoreData = true;
    
            int hoursWorked;
            int hourlyPay;
            int weeklyPay;
    
                String theName;
                System.out.println("Please enter employee name:");  //allows name to be supplied into the program
                theName = input.nextLine();   //sets the employee name
                
    
           System.out.println("Please enter number of hours worked:");   //allows number of hours to be inputted
           hoursWorked = input.nextInt();   //sets the number of hours worked
    
           System.out.println("Please enter the hourly pay rate:");   //allows for the hourly rate to be inputted
           hourlyPay = input.nextInt();   //sets the hourly pay rate
    
           weeklyPay = hoursWorked * hourlyPay;   //multiplies the number of hours by hourly pay rate
    
           System.out.printf ("Employee Name: % will be paid $%d%n", theName,weeklyPay);
           // displays the total rate of pay with the employee name
           
           //end main method
                
            }
    The following is the error message I get when I run the program...


    PHP Code:
    run:
    Welcome to Payroll Program Part 1
    Please enter employee name:
    Kiska
    Please enter number of hours worked:
    5
    Please enter the hourly pay rate:
    5
    Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'w'
            at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2603)
            at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2631)
            at java.util.Formatter.parse(Formatter.java:2477)
            at java.util.Formatter.format(Formatter.java:2411)
            at java.io.PrintStream.format(PrintStream.java:899)
            at java.io.PrintStream.printf(PrintStream.java:800)
            at payroll1.Payroll1.main(Payroll1.java:44)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 12 seconds)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Here:
    Java Code:
    System.out.printf ("Employee Name: % will be paid $%d%n", theName,weeklyPay);
    You're missing an "s":
    Java Code:
    System.out.printf ("Employee Name: %s will be paid $%d%n", theName,weeklyPay);
    the %s tells printf to place the results of the String variable theName in this spot.

  3. #3
    KiskaBaker is offline Member
    Join Date
    Aug 2009
    Location
    Georgia
    Posts
    2
    Rep Power
    0

    Smile Thanks!

    I appreciate the input! Works perfectly now!:)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Integer troubles
    By Tb0h in forum New To Java
    Replies: 11
    Last Post: 08-13-2009, 04:56 PM
  2. Gif decoding/LZW troubles
    By hellochar in forum Advanced Java
    Replies: 2
    Last Post: 07-14-2009, 11:26 PM
  3. Payroll Program exits at wrong time
    By jsand2 in forum Java Applets
    Replies: 13
    Last Post: 01-26-2009, 03:10 AM
  4. help for payroll project in java
    By mageshwari in forum New To Java
    Replies: 2
    Last Post: 04-09-2008, 02:46 AM
  5. Payroll Part 2, Java
    By lplopez92 in forum New To Java
    Replies: 2
    Last Post: 03-24-2008, 01:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •