Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA The data file provided above has a list of names, hourly salary and hours w

ID: 3838157 • Letter: J

Question

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.

Please explain steps , use simple program with information up to chapter 6

Explanation / Answer

Hi,

This is the code :

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class HelloWorld{

public static void main(String []args){
try {

File f = new File("data.txt");
int hours = 0;
float pay = 0;
int tax;
BufferedReader b = new BufferedReader(new FileReader(f));

String readLine = "";

while ((readLine = b.readLine()) != null) {
String[] tokens = readLine.split(" ");
int i = 2;
float netPay = 0;
while (i < tokens.length)
{
int temp = Integer.valueOf(tokens[i]);
hours = hours + temp;
i++;
}
float temp1 = Float.valueOf(tokens[1]);
pay = hours * temp1;
if ( pay > 400)
{
tax = 33;
}
else
{
tax = 25;
}
netPay = pay*tax/100;
System.out.println(tokens[0] + " worked for a total of: " + hours + " hours at $" + tokens[1] + " an hour for a gross pay of $" + pay);
System.out.println("After " + tax + "% taxes her total net pay should be " + netPay );
}

} catch (IOException e) {
e.printStackTrace();
}
}
}

The code is quite simpler to understand.

1) I used Buffered Reader to open a file called data.txt present in my current directory.

2) I used readline function to read through wach and every line.readline return NULL when there are no lines to read.

3) I stored the value of the lines in token separated by space.

4) Then i calculated taxes and pay as per the formula given.

Let me know if you dont understand any point.

Thanks

Nikhil Jain