Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.text.*;
- public class Prog213a
- {
- public static void main (String[] args) throws IOException
- {
- Scanner inFile=null;
- NumberFormat df = new DecimalFormat(".00");//rounding
- int d=0, hours, w=0;
- double d1=0, d2=0, d3=0, workWeek=0, bonus=0, salary=0;//initializes variables
- try
- {
- inFile = new Scanner (new File("prog213a.dat"));//pulls each number out individually from the file
- }
- catch(FileNotFoundException e)//in case it doesn't work
- {
- System.out.println("File not found!");
- System.exit(0);
- }
- while(inFile.hasNext())
- {
- String week=inFile.nextLine();
- Scanner read= new Scanner(week);
- w++;
- System.out.println("Hours worked: " + week);
- while(read.hasNext())
- {
- d=d+1;
- hours=read.nextInt();
- if(d==1)
- {
- d1=10*hours*1.5;
- }
- else if(d==2 || d==3 || d==4 || d==5 || d==6)
- {
- if(hours>8)
- {
- bonus=(hours-8)*1.5;
- }
- workWeek+=hours;
- d2+=(hours*10)+bonus;
- }
- else if(d==7)
- {
- d3=hours*10*2.25;
- }
- salary=d1+d2+d3;
- }
- System.out.println("Week # " + w + " $" + df.format(salary));
- }
- inFile.close();//shuts file
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement