# Simple Employee Payment Program

• November 20th, 2012, 03:53 PM
djl1990
Simple Employee Payment Program
Hi all,

I am struggling with a small program which calculates an employee's payment due.

Some basic points:

* Min Wage as 6.21
* Hours over first 40 is payed at 1.5
* Program should output the payment due

As you can see below i am using if statements to try and do this.

I have looked through several times but cant work out where the problem is.

Code :

```package latesttasks;   import java.util.*;   // Write a program that reads two numbers from the command line, the number of // hours worked by an employee and their base pay rate. Then output the // total pay due. Ensure the base pay rate entered is over minimum wage, if it // doesnt meet minimum wage print a warning and ask again for correct wage. // After 40 hour mark, pay rate is 150% or i.e. * 1.5. public class Task2 {   public static void main(String[] args) {   Scanner scan = new Scanner(System.in);   double hoursWorked; double minimumWage = 6.21; double baseRate; double overtimeRate; double amountDue; int hoursLimit = 40;   System.out.println("Please enter your basic hourly rate: "); baseRate = scan.nextInt();   if (baseRate < minimumWage) { System.out.println("Warning! rate doesn't meet minimum wage."); System.out.println(""); } System.out.println("How many hours have you worked this week: "); hoursWorked = scan.nextInt(); System.out.println(""); if (hoursWorked <= 0) { System.out.println("You are due no payment."); } else if (hoursWorked > hoursLimit) { overtimeRate = baseRate * 1.5; amountDue = (baseRate * hoursLimit) + ((hoursWorked - hoursLimit) * overtimeRate); System.out.println(amountDue); } else { amountDue = (hoursWorked * baseRate); System.out.println(amountDue); } } }```

• November 20th, 2012, 04:23 PM
curmudgeon
Re: Simple Employee Payment Program
How exactly is your program misbehaving?
• November 20th, 2012, 04:27 PM
CosmicCode
Re: Simple Employee Payment Program
hello djl1990
can you please specify the problem you're having ?
is it a calculation problem or a code problem?
which part of the code do you have problem with ?

I just did a modification on a little part of the code, hope it's correct !

Code :

```import java.util.*;   // Write a program that reads two numbers from the command line, the number of // hours worked by an employee and their base pay rate. Then output the // total pay due. Ensure the base pay rate entered is over minimum wage, if it // doesnt meet minimum wage print a warning and ask again for correct wage. // After 40 hour mark, pay rate is 150% or i.e. * 1.5. public class Task2 {   public static void main(String[] args) {   Scanner scan = new Scanner(System.in);   double hoursWorked; double minimumWage = 6.21; double baseRate; double overtimeRate; double amountDue; int hoursLimit = 40;   while(true){// to go over this, until the input is > minimumWage. System.out.println("Please enter your basic hourly rate: ");// baseRate = scan.nextInt(); if (baseRate < minimumWage) { System.out.println("Warning! rate doesn't meet minimum wage."); System.out.println(""); } else // if baseRate is > minimumWage, break the loop. break; }   System.out.println("How many hours have you worked this week: "); hoursWorked = scan.nextInt(); System.out.println(""); if (hoursWorked <= 0) { System.out.println("You are due no payment."); } else if (hoursWorked > hoursLimit) { overtimeRate = baseRate * 1.5; amountDue = (baseRate * hoursLimit) + ((hoursWorked - hoursLimit) * overtimeRate); System.out.println(amountDue); } else { amountDue = (hoursWorked * baseRate); System.out.println(amountDue); } } }```
• November 20th, 2012, 05:20 PM
djl1990
Re: Simple Employee Payment Program
Here was the error i was getting:

Quote:

run:
12.79
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
Java Result: 1
BUILD SUCCESSFUL (total time: 4 seconds)

--- Update ---

Thanks for the advice CosmicCode. I added the while true parts and break statement so now have this:

Code :

```package latesttasks;   import java.util.*;   // Write a program that reads two numbers from the command line, the number of // hours worked by an employee and their base pay rate. Then output the // total pay due. Ensure the base pay rate entered is over minimum wage, if it // doesnt meet minimum wage print a warning and ask again for correct wage. // After 40 hour mark, pay rate is 150% or i.e. * 1.5. public class Task2 {   public static void main(String[] args) {   Scanner scan = new Scanner(System.in);   double hoursWorked; double minimumWage = 6.21; double baseRate; double overtimeRate; double amountDue; int hoursLimit = 40;   while (true) { System.out.println("Please enter your basic hourly rate: "); baseRate = scan.nextInt();   if (baseRate < minimumWage) { System.out.println("Warning! rate doesn't meet minimum wage."); System.out.println(""); } else { break; } } System.out.println("How many hours have you worked this week: "); hoursWorked = scan.nextInt(); System.out.println(""); if (hoursWorked <= 0) { System.out.println("You are due no payment."); } else if (hoursWorked > hoursLimit) { overtimeRate = baseRate * 1.5; amountDue = (baseRate * hoursLimit) + ((hoursWorked - hoursLimit) * overtimeRate); System.out.println(amountDue); } else { amountDue = (hoursWorked * baseRate); System.out.println(amountDue); } } }```

However i am getting the following:

Quote:

run:
10.49
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
• November 21st, 2012, 06:53 AM
CosmicCode
Re: Simple Employee Payment Program
Now you specified it, thank you for that! .

the problem is this code : baseRate = scan.nextInt();

it takes the next integer value, but when you input a double value an error occurs.

so just change it to > baseRate = scan.nextDouble();

and this should work !

hope this helped !