Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import java.util.Scanner;
  4.  
  5. public class Prog213a
  6. {
  7.     public static void main(String [] args)
  8.     {
  9.         Scanner inFile = null;
  10.         try
  11.         {
  12.             // Create a scanner to read the file, file name is parameter
  13.             inFile = new Scanner (new File("prog213a.dat"));
  14.         }
  15.         catch (FileNotFoundException e)
  16.         {
  17.             System.out.println ("File not found!");
  18.             // Stop program if no file found
  19.             System.exit (0);
  20.         }
  21.        
  22.  
  23.        
  24.         do
  25.         {
  26.             int hours = 0;
  27.             int totalhours = 0;
  28.             int run = 1;
  29.             double pay = 0; //Daily Pay
  30.             double total = 0; //Total Pay
  31.             double overtime = 0;
  32.            
  33.             System.out.print("Hours Worked: ");
  34.             while(run <= 7)
  35.             {
  36.                 hours = inFile.nextInt();
  37.                 System.out.print(hours + " ");
  38.                 overtime = hours - 8;
  39.                 if(run == 1) //Sun
  40.                 {
  41.                         pay = (hours * 10)*1.5;
  42.                 }
  43.                 else if(run == 7) //Sat
  44.                 {
  45.                         pay = (hours * 10)*2.25;
  46.                 }
  47.                 else //Mon - Thurs
  48.                 {
  49.                     if(overtime > 0) //More than 8 hour work day
  50.                     {
  51.                         pay = ((hours-overtime) * 10) + (overtime* 11.5);
  52.                     }
  53.                     else //Regular work day
  54.                     {
  55.                         pay = (hours * 10);
  56.                     }
  57.                 }
  58.                 run++;
  59.                
  60.                 total = total + pay;
  61.                 pay = 0;
  62.                 hours = 0;
  63.                 totalhours = totalhours + hours;
  64.             }
  65.             double bonus = 0; //For working over 40 hours
  66.             if(totalhours - 40 > 0)
  67.             {
  68.                 totalhours = totalhours - 40;
  69.                 bonus = totalhours * 2.5;
  70.                 total = total + bonus;
  71.             }
  72.             System.out.println("");
  73.             System.out.println("Weekly Pay: $" + total);
  74.         }while(inFile.hasNext());
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement