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 2 of 2

Thread: Payroll

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Payroll

    Im having a hard time. I have to
    get the overtime pay and hours calculated Im thinking there is something wrong in my if-else statment?

    import java.util.*;
     
    public class Payroll
    {
    	private static Scanner console = new Scanner(System.in);
    	public static void main(String args[])
    	{
     
    	int numberOfWeeks;
    	String employeeID;
    	String employeeName;
    	double pr; //pay rate
    	double pay;
    	int hw; //hours worked
    	double overtimeHours;
    	char moreEmployees;	
    	double monthlyPay;
    	double totalPay;
    	double overtimePay;
    	int hours;
    	double overtimeRate = 1.5;
     
     
     
     
     
    		System.out.println("Please enter number of weeks to process: ");
    		numberOfWeeks = console.nextInt();
     
    		do 
    		{
     
    			System.out.println("Please enter employeeID: ");
    			employeeID = console.next();
    			System.out.println("Please enter employeeName: ");
    			employeeName = console.next();
    			System.out.println("Please enter pay rate: ");
    			pr = console.nextDouble();
    			monthlyPay = 0;
    			for (int x = 1; x <= numberOfWeeks; x++)
    			{
    				System.out.println("Please enter hours worked: ");
    				hw = console.nextInt();
    				pay = hw * pr;
    				monthlyPay = monthlyPay + pay;
    			}
     
     
    				if ( hours > 40)
    				{
     
    					hw = 40;
    					overtimeHours = hours - 40;
    				}
    					else
    					{
    						hw = hours;
    						overtimeHours = 0;
     
    					}
     
    				pay = pr * hw; 
    				overtimePay = overtimeRate * overtimeHours; 
    				monthlyPay = pay + overtimePay; 
     
    			System.out.println("--------------------------------------------");
    			System.out.println("Employee: " + employeeName);
    			System.out.println("Pay: " + monthlyPay);
    			System.out.println("--------------------------------------------");
    			totalPay = totalPay + monthlyPay;
    			System.out.println("More employees? y/n");
    			moreEmployees = console.next().charAt(0);
    			}while (moreEmployees == 'Y' || moreEmployees == 'y');
     
     
    		System.out.println("--------------------------------------------");
    		System.out.println("--------------------------------------------");
    		System.out.println("Total Monthly Payroll: " + totalPay);
    		System.out.println("--------------------------------------------");
    		System.out.println("--------------------------------------------");
    		   }
    		}
    Last edited by Kesh486; September 6th, 2010 at 03:54 PM.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Payroll

    Give us a test case, and its results. Just giving the code is not as helpful when we dont know what is going wrong.