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.
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); } } }
Any advice and suggestions appreciated.