stripes
- 262
- 0
Homework Statement
I am to design a Java program that inputs some information about employees. Then the computer displays it on the screen.
Here is a code snippet:
Code:
System.out.println("You will now provide information for " + numberOfEmployees +
" employees.");
for(int i = 0; i < numberOfEmployees; i++)
{
System.out.print("Enter the employee's name: ");
[B]tempEmployeeName[i] = in.nextLine();[/B]
System.out.println(tempEmployeeName[i] + "'s employee number will be " + (1000+i));
tempEmployeeNumber[i] = 1000+(i+1);
System.out.print("Enter " + tempEmployeeName[i] + "'s address: ");
tempEmployeeAddress[i] = in.nextLine();
System.out.print("Enter " + tempEmployeeName[i] + "'s salary: ");
tempEmployeeSalary[i] = in.nextDouble();
System.out.print("How many bonuses, if any, would you like for " + tempEmployeeName[i] + ": ");
tempBonus[i] = in.nextInt();
while(tempBonus[i] >= 10)
{
System.out.println("You have entered more than 10, each employee may only have " +
"10 bonues or less. Please re-enter the number of bonuses for " + tempEmployeeName[i] + ": ");
tempBonus[i] = in.nextInt();
}
if(tempBonus[i] <= 0)
System.out.println("You have chosen not to enter any bonuses for " + tempEmployeeName[i] + ".");
else if (tempBonus[i] > 0)
{
for(int j = 0; j < tempBonus[i]; j++)
{
System.out.print("Enter the amount for bonus " + (j+1) + " for " + tempEmployeeName[i] + ": ");
tempEmployeeBonus[i][j] = in.nextDouble();
}
}
for(int l = 0; l < numberOfEmployees; l++)
emp[l] = new Employee(tempEmployeeName[l], tempEmployeeNumber[l], tempEmployeeAddress[l], tempEmployeeSalary[l], tempEmployeeBonus[i]);
}
The bold line is the only line giving me trouble. Here is the output (italicized text has been typed by ME the user):
Code:
You will enter information for some employees, and then the information will be displayed. We require at least two employees, but you may create more if you wish.
How many employees would you create: [I]2[/I]
You will now provide information for 2 employees.
[B]Enter the employee's name: [/B]'s employee number will be 1001
Enter 's address: [I]12[/I]
Enter 's salary: [I]12[/I]
How many bonuses, if any, would you like for :
I can enter ALL information properly, but the line that asks for the employee's name is completely skipped. It SHOULD NOT say "'s employee number will be 1001" unless I have typed in a string and then press the return key. I need for the user to press the return key before displaying "'s employee number will be 1001". I thought it might be because I'm using a loop, but that can't be it as I am able to enter the address, salary, etc. perfectly fine.
Homework Equations
None
The Attempt at a Solution
See above code. Your help is much appreciated.