Skip to content

Instantly share code, notes, and snippets.

@imryan
Last active December 26, 2015 08:29
Show Gist options
  • Select an option

  • Save imryan/7122053 to your computer and use it in GitHub Desktop.

Select an option

Save imryan/7122053 to your computer and use it in GitHub Desktop.
Calculates payroll.
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