Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.text.*;
  4. public class Prog213a
  5. {
  6.     public static void main (String[] args) throws IOException
  7.     {
  8.         Scanner inFile=null;
  9.         NumberFormat df = new DecimalFormat(".00");//rounding
  10.         int d=0, hours, w=0;
  11.         double d1=0, d2=0, d3=0, workWeek=0, bonus=0, salary=0;//initializes variables
  12.             try
  13.             {
  14.                 inFile = new Scanner (new File("prog213a.dat"));//pulls each number out individually from the file
  15.             }
  16.             catch(FileNotFoundException e)//in case it doesn't work
  17.             {
  18.                 System.out.println("File not found!");
  19.                 System.exit(0);
  20.             }
  21.             while(inFile.hasNext())
  22.             {
  23.                 String week=inFile.nextLine();
  24.                 Scanner read= new Scanner(week);
  25.                 w++;
  26.                 System.out.println("Hours worked: " + week);
  27.                 while(read.hasNext())
  28.                 {
  29.                     d=d+1;
  30.                     hours=read.nextInt();
  31.                         if(d==1)
  32.                         {
  33.                             d1=10*hours*1.5;
  34.                         }
  35.                         else if(d==2 || d==3 || d==4 || d==5 || d==6)
  36.                         {
  37.                             if(hours>8)
  38.                             {
  39.                                 bonus=(hours-8)*1.5;
  40.                             }
  41.                             workWeek+=hours;
  42.                             d2+=(hours*10)+bonus;
  43.                         }
  44.                         else if(d==7)
  45.                         {
  46.                             d3=hours*10*2.25;
  47.                         }
  48.                         salary=d1+d2+d3;
  49.                     }
  50.                     System.out.println("Week # " + w + " $" + df.format(salary));
  51.                 }
  52.         inFile.close();//shuts file
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement