// Payroll2.java
// A program to calculate and print the department, name, and pay of an employee.
import java.util.Scanner; //program uses the Scanner class
import java.io.*;
public class Payroll2
{
// main method begins execution of Java program.
public static void main(String args[])
{
// create Scanner to obtain input from the command window
Scanner input = new Scanner (System.in);
double number1; // first number to multiply
double number2; // second number to multiply
double product; // product of number1 and
String name; // give the variable a name ( "name" in this case)
do
{
System.out.print("Enter Department name: "); //prompt
name = input.nextLine(); // read name from user
System.out.print("Enter number of employees: "); // prompt
number1 = input.nextDouble(); // read first number from user
System.out.print("Enter average salary: "); // prompt
number2 = input.nextDouble(); // read second number from user
product = number1 * number2; // multiply numbers
System.out.println("Department name:" + name); // display Department name
System.out.printf("Payroll is: $%.2f\n", product); // display product
}
while (!name.equals("stop"));
} // end method main
} // end class Payroll2
Hello, I am new to programming, but I have had minor success in learning through trial and error (as well as looking at code snippets). I seem to be having a bit of trouble understanding where I am going wrong and why I have encountered an infinite loop here. Any help that could be given would be greatly appreciated

New Topic/Question
Reply



MultiQuote




|