My program compiles without any errors, however, when I go to run it all I get is a message saying "Welcome to the Payroll Program". From there it does not print anything else nor allows me to enter any information. If someone could please take a look at my program and let me know what I am overlooking, I'm new to looping and I believe my issue is somewhere within my looping structures. It would be greatly appreciated!! :)

// Fig. 1.1: Payroll Part 2
// Payroll program calculates employee's weekly pay.

import java.util.Scanner;// program to use import scanner

public class PayrollPart2
{
   //main method begins execution of java program execution
   public static void main( String args[] )
   {
      System.out.println( "Welcome to the Payroll Program!" );

      boolean stop = false; // Loop until user types "stop" as the employee name.
            while (!stop);
      {
          // create scanner to obtain input from command window
          Scanner input = new Scanner(System.in );

          System.out.println();  // outputs a blank line
          System.out.print( "Enter Employee's Name or stop to exit program: " );
          String empName = input.nextLine(); // employee name

          if ( empName.equals("stop"))
                  {
                    System.out.println( "Program Exited" );
                    stop = true;
                  }
          else
          {
             float hourlyRate; // hourly rate
             float hoursWorked; // hours worked
             float weeklyPay; // Weekly Pay for employee

             System.out.print( "Enter hourly rate: " ); // prompt for hourly rate
             hourlyRate = input.nextFloat();

             while (hourlyRate <= 0) // prompt until positive value is entered
             {
                System.out.print( "Hourly rate must be a positive number. " +
                         "Please enter the hourly rate again: " );
                        hourlyRate = input.nextFloat(); // read hourly rate again
                    }

                    System.out.print( "Enter hours worked: " ); // prompt for hours worked
                    hoursWorked = input.nextFloat();


                    while (hoursWorked <= 0) // prompt until a positive value is entered
                    {
                       System.out.print( "Hours worked must be a positive number. " +
                         "Please re-enter hours worked: " ); // prompt for positive value for hours worked
                        hoursWorked = input.nextFloat(); // read hours worked again
                    }

                    // Calculate Weekly Pay.

                    weeklyPay = (float) hourlyRate * hoursWorked; // multiply sum

                    // Display Output Results and sum

                    System.out.print( empName ); // display employee name
                    System.out.printf( "'s weekly pay is: $%,.2f\n", weeklyPay);  // display weekly pay

                  }
                }

                // Display ending message:
                System.out.println( "Closing Payroll Program." );
                System.out.println(); // outputs a blank line

             } // end method main

          } // end class PayrollPart2

Recommended Answers

All 5 Replies

Please use code tags...

//place code statements within brackets

"["code=java"]"

// insert code here...

"["code"]"

Get rid of the quotes when doing this

Sorry! I have placed my code tags. Thanks for letting me know.

// Fig. 1.1: Payroll Part 2
// Payroll program calculates employee's weekly pay.

import java.util.Scanner;// program to use import scanner

public class PayrollPart2
{
//main method begins execution of java program execution
public static void main( String args[] )
 {
  System.out.println( "Welcome to the Payroll Program!" );

  boolean stop = false; // Loop until user types "stop" as the employee name.
  while (!stop);
  {
  // create scanner to obtain input from command window
  Scanner input = new Scanner(System.in );

  System.out.println();  // outputs a blank line
  System.out.print( "Enter Employee's Name or stop to exit program: " );
  String empName = input.nextLine(); // employee name

   if ( empName.equals("stop"))
   {
	System.out.println( "Program Exited" );
	stop = true;
   }//end if

   else
	{
     float hourlyRate; // hourly rate
	 float hoursWorked; // hours worked
	 float weeklyPay; // Weekly Pay for employee

  System.out.print( "Enter hourly rate: " ); // prompt for hourly rate
  hourlyRate = input.nextFloat();

    while (hourlyRate <= 0) // prompt until pos. value is entered
	 {
	  System.out.print( "Hourly rate must be a positive number. " +
	   "Please enter the hourly rate again: " );
	  hourlyRate = input.nextFloat(); // read hourly rate again
	  }//end while

	  }//end else

  	System.out.print( "Enter hours worked: " ); // prompt for hours worked
  	hoursWorked = input.nextFloat();


     while (hoursWorked <= 0) // prompt until positive value is entered
	  {
	   System.out.print( "Hours worked must be a positive number. " +
	    "Please re-enter hours worked: " ); // prompt for positive value
	   hoursWorked = input.nextFloat(); //
	   }//end while

  	// Calculate Weekly Pay.

  	weeklyPay = (float) hourlyRate * hoursWorked; // * sum

  	// Display Output Results and sum

  	System.out.print( empName ); // display employee name
  	System.out.printf( "'s weekly pay is: $%,.2f\n", weeklyPay);//display weeklypay


  	// Display ending message:
  	System.out.println( "Closing Payroll Program." );

	} // end method main

 } // end class PayrollPart2

Take a look at the end of line 14 where you have the while statement. See anything that perhaps should not be there?

can anyone help me pls....
So I have to write a program which calcualates the pay for each 5 employees. Sovle this problem using methods. You have to use arrays and in two different classes.

I can't understand how do it. I did it without arrays though...and everything is ok.... This is it :-

class payroll
{
   int hours;
   double payrate;

   payroll(int h, double prate)
   {
       hours=h;
       payrate=prate;
    }
    int hours()
    {
        return hours;
    }

    double payrate()
    {
        return payrate;
    }

    double wage()
    {
        return payrate*hours;
    }
}

and the main class is this:-

import java.util.Scanner;
  class use_payroll {
    public static void main(String args[]) {

        Scanner sc =new Scanner(System.in);
        System.out.println("Please enter hours" );
           int hrs=sc.nextInt();
           System.out.println("Please enter rate" );
             double rate=sc.nextDouble();
              payroll p=new payroll(hrs,rate);


              System.out.println("The wage for "+p.hours()+"hours "+"at a rate of "+p.payrate()+"is "+p.wage());
            }
        }

Tizzie: what are you doing? Make your own thread and post code in code tags and read the rules first.

brizwhiz's only problem appears to be what ezzaral pointed out, the semi-colon should not be there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.