Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.util.Scanner;
- public class Prog213a
- {
- public static void main(String [] args)
- {
- Scanner inFile = null;
- try
- {
- // Create a scanner to read the file, file name is parameter
- inFile = new Scanner (new File("prog213a.dat"));
- }
- catch (FileNotFoundException e)
- {
- System.out.println ("File not found!");
- // Stop program if no file found
- System.exit (0);
- }
- do
- {
- int hours = 0;
- int totalhours = 0;
- int run = 1;
- double pay = 0; //Daily Pay
- double total = 0; //Total Pay
- double overtime = 0;
- System.out.print("Hours Worked: ");
- while(run <= 7)
- {
- hours = inFile.nextInt();
- System.out.print(hours + " ");
- overtime = hours - 8;
- if(run == 1) //Sun
- {
- pay = (hours * 10)*1.5;
- }
- else if(run == 7) //Sat
- {
- pay = (hours * 10)*2.25;
- }
- else //Mon - Thurs
- {
- if(overtime > 0) //More than 8 hour work day
- {
- pay = ((hours-overtime) * 10) + (overtime* 11.5);
- }
- else //Regular work day
- {
- pay = (hours * 10);
- }
- }
- run++;
- total = total + pay;
- pay = 0;
- hours = 0;
- totalhours = totalhours + hours;
- }
- double bonus = 0; //For working over 40 hours
- if(totalhours - 40 > 0)
- {
- totalhours = totalhours - 40;
- bonus = totalhours * 2.5;
- total = total + bonus;
- }
- System.out.println("");
- System.out.println("Weekly Pay: $" + total);
- }while(inFile.hasNext());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement