Source of Overtime.java


  2: import java.util.Scanner;

  4: /**
  5:  * Calculate the user's weekly pay.
  6:  *
  7:  * @author Mark Young (A00000000)
  8:  */
  9: public class Overtime {

 11:     public static void main(String[] args) {
 12:         // create variables
 13:         Scanner kbd = new Scanner(System.in);
 14:         double rate, hours, pay;

 16:         // introduce yourself
 17:         System.out.println("\n"
 18:                 + "This program calculates you pay and writes a cheque.\n");

 20:         // get pay information
 21:         System.out.print("What is your hourly wage? ");
 22:         rate = kbd.nextDouble();
 23:         kbd.nextLine();
 24:         System.out.print("How many hours did you work this week? ");
 25:         hours = kbd.nextDouble();
 26:         kbd.nextLine();

 28:         // calculate pay
 29:         pay = rate * hours;
 30:         if (hours > 40) {
 31:             System.out.println("You get overtime pay.");
 32:             pay = pay + rate * 0.5 * (hours - 40);
 33:         }

 35:         // issue cheque
 36:         System.out.println("\n"
 37:                 + "Pay to the order of BEARER\n"
 38:                 + "$" + String.format("%,.2f", pay) + "\n"
 39:                 + "Bank of ImaginationLand\n");
 40:     }

 42: }