Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Java Wages Calculation

$
0
0
Hi There,

I need help with an assignment I have... The assignments description is:
You just started working as a programmer. You are paid $10 an hour, with a few exceptions. You earn an extra $1.50 an hour for any part of a day where you work more than 8 hours, and an extra $2.50 an hour for hours beyond 40 in any one week. You also earn a 125% bonus for working on Saturday, and a 50% bonus for working on Sunday. The bonuses for Saturday and Sunday are computed based on the hours worked those days; they are not used to calculate any bonus for working more than 40 hours in a week.

Your input file will be the number of hours you worked each day in the week beginning with Sunday. You need to write a program that will continue processing the file to calculate your gross pay for each week worked until the end of file is reached. Each line of input will consist of one weeks hours (7 integers per line, each less than or equal to 24). Ouput the gross pay with a dollar sign rounded to the nearest penny for each week worked.

This is my code:
import java.util.Scanner;
import java.io.*;
class WeirdWages
{
   public static void main(String args[])
   {
   try
   {
       FileReader data = new FileReader("data.txt");
       BufferedReader numBuffer = new BufferedReader(data);
       Scanner numScan = new Scanner(numBuffer);
       
       int i = 0;

       System.out.print("Hours Worked: ");
       while(numScan.hasNextInt())
       {  
           int n = numScan.nextInt(); 
          i++;
           if(i<8)
           {
             System.out.print(n+" ");
            }
        }
        
       numScan.close();
    }  
    catch (Exception e)
    {
        System.err.println("Error");
    }
  }
}

data.txt looks like this:
9 8 10 8 9 9 5
7 8 8 8 0 8 9
6 10 5 0 0 0 0

and the output when everything is done should look like this:
Hours Worked: 9 8 10 8 9 9 5 Week # 1 $703.50
Hours Worked: 7 8 8 8 0 8 9 Week # 2 $627.50
Hours Worked: 6 10 5 0 0 0 0 Week # 3 $243.00
Hours Worked: End of reading from file.

If anyone can help me that would be great! Thanks!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>