1. Using a loop of your choice, read information from the console about employee
ID: 3754483 • Letter: 1
Question
1. Using a loop of your choice, read information from the console about employees in a company. Each employee has an ID (integer) and number of hours worked that week (double) and hourly pay rate double) a. After you read in an employee' s information, you will calculate the salary for that week by multiplying the number of hours worked by the hourly rate. Number of hours and hourly rate should be real numbers with one or two decimal places b. Print a statement clearly indicating the employee ID, number of hours worked, hourly rate and the total salary for that week c. Use a counter varlable to keep track of how many employees were processed d. Continue reading information for all employees, processing and printing the information as above until the ID less than or equal to 0. When the ID is or less, you should not be entering hours worked or hourly rate. This reans you should read ID separately and continue reading the rest of the data per employee only 1f ID is 1 e. When the loop is done, print the total number of employees processed by the program and the total salary of all employees f. Print the program and the output 2. Now add to your program print statements so that the hours worked and salary wi11 print with two decimal places. Create fixed columns for each piece of data (ID, hors worked, hourly rate and total salary)Numbers should be right adjusted so the dollars and cents line up. Run the program again with the sare data and see what the output looks like now. Print the program and the output 3. Add an if-else statement in your program to compute tax on the salary. If the salary is less than $300, the tax rate is .03, if salary is between $300 and $350 the tax rate is .04 otherwise the tax rate is .05. Compute the tax by multiplying the salary by the tax rate. Add the tax as another column of your output table. Print the program and the output Use these values as input to cover all three tax groups 12.5 15.8 18.9 20.25 rateExplanation / Answer
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts. Thanks
// EmployeeSalary.java
import java.util.Scanner;
public class EmployeeSalary {
public static void main(String[] args) {
//defining scanner to read input
Scanner scanner = new Scanner(System.in);
//initializing required variables
int count = 0;
int id = 0;
double numHours, payRate, salary, tax, totalSalary = 0;
//using a do while loop to process input
do {
//getting id
System.out.print("Enter employee ID: ");
id = scanner.nextInt();
//checking if id is greater than zero
if (id > 0) {
//getting hours and payrate
System.out.print("Enter number of hours worked: ");
numHours = scanner.nextDouble();
System.out.print("Enter hourly pay rate: ");
payRate = scanner.nextDouble();
//finding salary
salary = payRate * numHours;
//finding tax
if (salary < 300) {
tax = salary * 0.03;
} else if (salary >= 300 && salary <= 350) {
tax = salary * 0.04;
} else {
tax = salary * 0.05;
}
//displaying everything in a formatted output
System.out.printf("Hours worked: %.2f, Hourly Payrate: $%3.2f,"
+ " Salary: $%6.2f, Tax: $%.2f ", numHours, payRate,
salary, tax);
count++; //incrementing number of employees processed
totalSalary += salary; //adding to total salary
}
} while (id > 0);
//displaying number of employees and total salary
System.out.printf(
"A total of %d employees processed, total salary: $%.2f ",
count, totalSalary);
}
}
/*OUTPUT*/
Enter employee ID: 101
Enter number of hours worked: 12.5
Enter hourly pay rate: 15.8
Hours worked: 12.50, Hourly Payrate: $15.80, Salary: $197.50, Tax: $5.93
Enter employee ID: 102
Enter number of hours worked: 15.25
Enter hourly pay rate: 21.2
Hours worked: 15.25, Hourly Payrate: $21.20, Salary: $323.30, Tax: $12.93
Enter employee ID: 111
Enter number of hours worked: 18.9
Enter hourly pay rate: 20.25
Hours worked: 18.90, Hourly Payrate: $20.25, Salary: $382.72, Tax: $19.14
Enter employee ID: 0
A total of 3 employees processed, total salary: $903.52
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.