Last active
December 26, 2015 08:29
-
-
Save imryan/7122053 to your computer and use it in GitHub Desktop.
Calculates payroll.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| import java.text.*; | |
| public class Payroll { | |
| public static void main(String[] args) | |
| { | |
| // Declare variables | |
| Scanner sc = new Scanner(System.in); | |
| double wage = 0.0, hours = 0.0; | |
| // Input request | |
| System.out.println("Enter your wage: "); | |
| wage = sc.nextDouble(); | |
| System.out.println("Enter your hours: "); | |
| hours = sc.nextDouble(); | |
| // Create NumberFormat and calculate payroll | |
| NumberFormat nf = NumberFormat.getCurrencyInstance(); | |
| System.out.println("\nPayroll: " + nf.format(getPayroll(wage, hours))); | |
| } | |
| public static double getPayroll(double wage, double hours) | |
| { | |
| // Store original value of hours in time in case of change | |
| double time = hours; | |
| if (time > 40) | |
| { | |
| return ((time / 2) + hours) * wage; | |
| } | |
| return wage * hours; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment