I've been at this for a while now, and cant seem to figure out why it is behaving this way. After the program runs through the first time it doesn't wait for input for the division name prompt. I know its some form of syntactical error on my behalf, I just can't for the life of me figure it out.
//payroll
import java.util.Scanner;
public class Payroll
{
public static void main(String[] args)
{
//create scanner object for inputs
Scanner input = new Scanner(System.in);
String name = "Null";
//create instance of class Division
Division newDivision1 = new Division();
//prompt for new division name.
do {
System.out.println( "Please Enter the Division Name. Enter \"stop\" to exit: " );
name = input.nextLine();
System.out.println();
if (!name.equals("stop"))
{
newDivision1.setDivName(name); //set name of object instance to input name.
//prompt for employees
System.out.println("Please input the number of employees for " + newDivision1.getDivName() + ".");
int employees = input.nextInt(); //capture int value of employees
System.out.println();
if (employees < 0)
{
do {
System.out.printf("Please input a positive value for the number of employees:\n");
employees = input.nextInt();
} while (employees < 0);
}
newDivision1.setDivEmployees(employees); //set employees to object instance
//prompt for average salary
System.out.println("Please input the average salary for " + newDivision1.getDivName() + ". \nPlease enter as digits and decimal only, \nexclude \"$\" and comma's.\n");
double salary = input.nextFloat(); //capture average salary as float
if (salary < 0)
{
do {
System.out.printf("Please input a positive value for the average salary: \n");
salary = input.nextFloat();
} while (salary < 0);
}
newDivision1.setAvgSalary(salary);//set average salary to object instance
//output totals
System.out.printf("The %s division contains %d employees with an average salary of $%.2f.\n", newDivision1.getDivName(), newDivision1.getDivEmployees(), newDivision1.getAvgSalary());
System.out.printf("The total payroll for the division is $%.2f.\n", newDivision1.getTotalSalary());
}
} while (!name.equals("stop"));
System.out.println( "The Program will now Exit.\n");
}//end main
}//end payroll
formatting inst quite right, but that's the basic program.
Any help would be greatly appreciated!
ADDED: As per the comment, I created 3 different scanners for inputting floats, strings, and ints all separately and it solved the problem perfectly!
Lesson learned, THANK YOU!!