Skip to content

Instantly share code, notes, and snippets.

@JorgeOlvera
Created November 6, 2013 14:54
Show Gist options
  • Save JorgeOlvera/7337318 to your computer and use it in GitHub Desktop.
Save JorgeOlvera/7337318 to your computer and use it in GitHub Desktop.
/*4. An employee receives the regular pay rate for the first 30 hours and he is paid 1½
times the normal rate for each hour over the 30 hours. Write a program (save it as
BonusWage) that prompts the user for the regular pay rate and the hours worked and
then it will calculate and display on screen the employee’s wage based on that
information and the criteria mentioned above. For example, if 42 is entered for hours and
6.00 for rate, then the amount to display should be $288.00.
*/
import java.util.Scanner;
import java.io.*;
public class BonusWage {
public static void main(String[] args) {
String wage;
String hours
Scanner input = new Scanner(System.in);
System.out.println("Enter your wage");
wage = input.nextLine();
System.out.println("Enter the amount of hours you worked")
hours = input.nextLine();
if (hours <= 30){
System.out.println("Your total salary is:" + wage * hours);
}
else if (hours > 30) {
System.out.println("Your total salary is" + wage * 1.5 *hours)
}
}
}
@g-i-o-
Copy link

g-i-o- commented Nov 6, 2013

The second if should be:
System.out.println("Your total salary is" + wage * (30 + 1.5 *(hours-30) ) );
since the 1.5 is applied to each hour in addition to the 30 hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment