I cannot for the life of me figure out what I am doing wrong, I feel like it is something realllllyyyyyyy tiny. It runs fine the first time, but then it skips the part where I ask for user to input Dept Name. When I type stop I get some crazy error. Also there is something wrong with my validation while loops, as it prompts the user to input a positive value, but immediately exits the loop and continues to the next line.// Thomas Harrald IT215 // Checkpoint Payroll Program Two import java.util.Scanner; //Import Scanner public class PayrollProgramtwo { public static void main( String[] args ) { Scanner input = new Scanner (System.in); String deptName; int numberEmployees; float avgSalary; float totalDept; boolean end = false; System.out.println( "Welcome to the Payroll Program" ); while (end == false) { System.out.println( "Please input the name of the department type stop to end." ); deptName = input.next(); if(deptName.toLowerCase().equals( "stop")) end = true; System.out.println( "Please input the number of employees" ); numberEmployees = input.nextInt(); while (numberEmployees < 0 ) { System.out.println ( "Please input a positive number"); numberEmployees = input.nextInt(); } System.out.println( "Please input the average employee salary" ); avgSalary = input.nextFloat(); while ( avgSalary < 0 ) { System.out.println ( " Please input a positive number"); avgSalaray = input.nextFloat(); } totalDept = numberEmployees * avgSalary; System.out.printf( "The name of the department is %s\n ", deptName ); System.out.printf( "The total payroll is $%sUSD ", totalDept); } System.out.println( "Thank you for using the Payroll Program!"); } }
This is a homework assignment, and no it's not due today. I turned this is a while ago and got most credit, but I really want to know where I went wrong. Please, any help would be greatly appreciated.
Thanks!