JAVA The data file provided above has a list of names hourly
JAVA
The data file provided above has a list of names, hourly salary and hours worked per day.
Your assignment is for each person on the list, find their total salary for the week and print out the vital info.
For example, the first like of the data file looks like
This should print out the following:
For taxes, if a person has a gross pay of $400 or more their taxes are 33% of the gross, otherwise it is 25%.
Note that not every person works 5 days, so you need to account for that. Also watch your decimals. Hours are all in integer values, while decimals need to be rounded to two decimal places.
this is the TXT link: https://drive.google.com/open?id=0B1IThl7l1PdKaW1RdlA1Q095dmc
dont use \"try\" plz. just use \"while\", and \"if\" no more farther.
Solution
Here is the code for you:
import java.util.*;
import java.io.*;
class EmployeeSalaryCalc
{
public static void main(String[] args) throws IOException
{
String line;
Scanner sc = new Scanner(new File(\"SalaryDetails.txt\"));
while(sc.hasNextLine())
{
line = sc.nextLine();
String[] tokens = line.split(\" \");
System.out.println(tokens.length);
String name = tokens[0];
System.out.println(tokens[1]);
double hourlyRate = Double.parseDouble(tokens[1]);
System.out.println(hourlyRate);
int totalHours = 0;
for(int i = 2; i < tokens.length; i++)
totalHours += Integer.parseInt(tokens[i]);
double totalPay = totalHours * hourlyRate;
System.out.printf(\"%s worked for a total of: %d hours at $%.2f an hour for a gross pay of $%.2f.\ \", name, totalHours, hourlyRate, totalPay);
System.out.printf(\"After 25% taxes her total net pay should be $%.2f.\ \ \", 0.75*totalPay);
}
}
}
