Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Please help me with this payroll program

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    18
    My Mood
    Nerdy
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Please help me with this payroll program

    So I designed a payroll program. It works like so:
    The program prompts you to enter the first name and then prompts you to enter the last name of the employee.
    Then it prompts you to enter the employee's skill level. i.e.(skill level 1= 7 dollars per hour, skill level 2= 10 dollars per hour, and skill level 3= 12 dollars per hour)
    Finally it prompts you to enter the hours worked. (The employees normal shift is 40 hours per week, if the employee worked more than this then they qualify for overtime pay. Overtime pay is the same amount they make on normal shift.

    This is the code:

     import javax.swing.JOptionPane;
    import javax.swing.JFrame;
     
    public class PayStuff
    {
    public static void main(String[] args) throws Exception
    {
     
    //Declaration of strings
    String firstName;
    String lastName;
    String skillLevel;
    String durationWorked;
     
     
    firstName= JOptionPane.showInputDialog("Please enter the employee's first name:");
    lastName= JOptionPane.showInputDialog("Please enter the employee's last name:");
    skillLevel= JOptionPane.showInputDialog("Please enter the employee's skill level:");
     
    int payRate;
     
    if (skillLevel.equals("1"))
    {
    payRate=7;
    }
    else if (skillLevel.equals("2"))
    {
    payRate=10;
    }
    else if (skillLevel.equals("3"))
    {
    payRate=12;
    }
     
    durationWorked= JOptionPane.showInputDialog("Please enter the duration worked in hours:");
     
    int hoursWorked= Integer.parseInt(durationWorked);
    int normalPay= payRate*hoursWorked;
    int overtimePay;
    int grossPay= normalPay+overtimePay;
     
    if (hoursWorked <= 40)
    {
    overtimePay=0;
    }
    else
    {
    overtimePay= normalPay;
    }
     
    String stpayRate=Integer.toString(payRate);
    String stnormalPay=Integer.toString(normalPay);
    String stovertimePay=Integer.toString(overtimePay);
    String stgrossPay=Integer.toString(grossPay);
     
    JOptionPane.showMessageDialog (null, firstName + lastName + skillLevel + payRate + normalPay + overtimePay + grossPay, 
     
    "Widget Company Payroll System", JOptionPane.INFORMATION_MESSAGE);
    {
    System.exit(0); //Exits the application
    }
    }
    }


    I am getting errors. Now I googled this exceptions before attempting to post here:

    C:\Program Files\Java\jdk1.6.0_24\bin>javac PayStuff.java
    PayStuff.java:38: variable payRate might not have been initialized
    int normalPay= payRate*hoursWorked;
                   ^
    PayStuff.java:40: variable overtimePay might not have been initialized
    int grossPay= normalPay+overtimePay;
                            ^
    2 errors

    I understand that when a variable is not initialized, it means that a value has not been assigned to that variable. But if you look I have assigned values to the variables... The other values require the user to input and the other rely on the IF function. Please help


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Please help me with this payroll program

    int payRate;
    int overtimePay;

    Not initialised
    Just give them a default value of 0.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. The Following User Says Thank You to newbie For This Useful Post:

    Leprechaun_hunter (April 14th, 2011)

  4. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    18
    My Mood
    Nerdy
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Please help me with this payroll program

    Muhahahahaha!.... Thank you!

Similar Threads

  1. Help with class program!!! STUCK! Program not doing what I Want!!!
    By sketch_flygirl in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2011, 07:29 AM
  2. heeeeeyyyy .. HELP ! :) -- PAYROLL SYSTEM --
    By princess in forum Java Theory & Questions
    Replies: 5
    Last Post: February 27th, 2011, 03:11 PM
  3. Payroll
    By Kesh486 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 6th, 2010, 06:48 PM