Question: This is my first code in java and for some reason my code works perfectly until it gets to the second employee. Then, it attempts
This is my first code in java and for some reason my code works perfectly until it gets to the second employee. Then, it attempts to read in the name and hourly rate at the same time.
package assignment1;
import java.util.Scanner; /* Author Name: * Description: Assignment 1 for ICS 141 will help calculate the proper pay * after taxes for 3 employees. * Due Date: 1/19/22 */ public class Assignment1 { public static void main(String[] args) { // This creates a tool for reading/entering in employee information Scanner scanner = new Scanner(System.in); int hourlyRate1, hoursWorked1, payBefore1 ; //declaration of integer variables double taxRate, payAfter1, taxTaken1, totalTaxHeld; //declaration of float variable int hourlyRate2, hoursWorked2, payBefore2 ; //declaration of integer variables double payAfter2, taxTaken2 ; //declaration of float variable int hourlyRate3, hoursWorked3, payBefore3 ; //declaration of integer variables double payAfter3, taxTaken3 ; //declaration of float variable System.out.println("Enter first employee's name: "); String name1 = scanner.nextLine(); //read in name System.out.println("Enter hourly rate:"); hourlyRate1 = scanner.nextInt(); //read char and convert to int System.out.println("Enter hours worked:"); hoursWorked1 = scanner.nextInt(); //read char and convert to int System.out.println("Enter tax rate as a percentage:"); taxRate = scanner.nextDouble(); payBefore1 = hourlyRate1 * hoursWorked1; //define and calculate pay before taxTaken1 = payBefore1 * (taxRate/100); payAfter1 = payBefore1 - taxTaken1; System.out.println("Enter second employee's name: "); String name2 = scanner.nextLine(); //read in name System.out.println("Enter hourly rate:"); hourlyRate2 = scanner.nextInt(); //read char and convert to int System.out.println("Enter hours worked:"); hoursWorked2 = scanner.nextInt(); //read char and convert to int payBefore2 = hourlyRate2 * hoursWorked2; //define and calculate pay before taxTaken2 = payBefore2 * (taxRate/100); payAfter2 = payBefore2 - taxTaken2; System.out.println("Enter third employee's name: "); String name3 = scanner.nextLine(); //read in name System.out.println("Enter hourly rate:"); hourlyRate3 = scanner.nextInt(); //read char and convert to int System.out.println("Enter hours worked:"); hoursWorked3 = scanner.nextInt(); //read char and convert to int payBefore3 = hourlyRate3 * hoursWorked3; //define and calculate pay before taxTaken3 = payBefore3 * (taxRate/100); payAfter3 = payBefore3 - taxTaken3; totalTaxHeld = taxTaken1 + taxTaken2 + taxTaken3; System.out.println("Employee: " + name1); System.out.println("Pay before taxes is: " + payBefore1); System.out.println("Amount taxed is: " + taxTaken1); System.out.println("Pay after taxed: " + payAfter1); System.out.println("Employee: " + name2); System.out.println("Pay before taxes is: " + payBefore2); System.out.println("Amount taxed is: " + taxTaken2); System.out.println("Pay after taxed: " + payAfter2); System.out.println("Employee: " + name3); System.out.println("Pay before taxes is: " + payBefore3); System.out.println("Amount taxed is: " + taxTaken3); System.out.println("Pay after taxed: " + payAfter3); System.out.println("Total taxes held by company: " + totalTaxHeld);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
