Need Help with Java for Payroll Program

Thread Solved

Join Date: Sep 2008
Posts: 40
Reputation: Coyboss is an unknown quantity at this point 
Solved Threads: 0
Coyboss Coyboss is offline Offline
Light Poster

Need Help with Java for Payroll Program

 
0
  #1
Jan 15th, 2009
I think I have 90+ percent of the coding right for this but I
am having an issue with the program stopping after the "welcome to payroll program statement"

I can't figure out what goes after while on the liine after the boolean stop line.

Any help would be greatly appreciated!!

IKE
  1.  
  2. package employee_pay;
  3.  
  4. // Payroll program calculates employee's weekly pay.
  5.  
  6. import java.util.Scanner;
  7.  
  8. public class pay{
  9. public static void main( String args[] )
  10. {
  11. System.out.println( "Welcome to the Payroll Program!" );
  12.  
  13. boolean stop = false; // Loop until user types "stop" as the employee name.
  14. while (!stop);
  15. {
  16. Scanner input = new Scanner(System.in );
  17.  
  18. System.out.println();
  19. System.out.print( "Enter Employee's Name or stop to exit program: " );
  20. String empName = input.nextLine();
  21.  
  22. if ( empName.equals("stop"))
  23. {
  24. System.out.println( "Program Exited" );
  25. stop = true;
  26. }
  27. else
  28. {
  29. float hourlyRate; // hourly rate
  30. float hoursWorked; // hours worked
  31. float weeklyPay; // Weekly Pay for employee
  32.  
  33. System.out.print( "Enter hourly rate: " ); // prompt for hourly rate
  34. hourlyRate = input.nextFloat();
  35.  
  36. while (hourlyRate <= 0) // prompt until positive value is entered
  37. {
  38. System.out.print( "Hourly rate must be a positive number. " +
  39. "Please enter the hourly rate again: " );
  40. hourlyRate = input.nextFloat(); // read hourly rate again
  41. }
  42.  
  43. System.out.print( "Enter hours worked: " ); // prompt for hours worked
  44. hoursWorked = input.nextFloat();
  45.  
  46.  
  47. while (hoursWorked <= 0) // prompt until a positive value is entered
  48. {
  49. System.out.print( "Hours worked must be a positive number. " +
  50. "Please re-enter hours worked: " ); // prompt for positive value for hours worked
  51. hoursWorked = input.nextFloat(); // read hours worked again
  52. }
  53.  
  54. // Calculate Weekly Pay.
  55.  
  56. weeklyPay = (float) hourlyRate * hoursWorked; // multiply sum
  57.  
  58. // Display Output Results and sum
  59.  
  60. System.out.print( empName ); // display employee name
  61. System.out.printf( "'s weekly pay is: $%,.2f\n", weeklyPay); // display weekly pay
  62.  
  63. }
  64. }
  65.  
  66. // Display ending message:
  67. System.out.println( "Closing Payroll Program." );
  68. System.out.println(); // outputs a blank line
  69.  
  70. } // end method main
  71.  
  72. } // end class Pay
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 686
Reputation: sillyboy is on a distinguished road 
Solved Threads: 61
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: Need Help with Java for Payroll Program

 
0
  #2
Jan 15th, 2009
hahaha this is a really unfortunate error:

  1. while (!stop);{

notice the semicolon (hence an infinite loop of empty statement)
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 40
Reputation: Coyboss is an unknown quantity at this point 
Solved Threads: 0
Coyboss Coyboss is offline Offline
Light Poster

Re: Need Help with Java for Payroll Program

 
0
  #3
Jan 15th, 2009
So do I need to delete the semicolon?
OR what do I need to change?

Thanks

IKE
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Need Help with Java for Payroll Program

 
0
  #4
Jan 15th, 2009
Delete it.

Also consider formatting your code properly:

  1. package employee_pay;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class pay
  6. {
  7. public static void main ( String args[] )
  8. {
  9. System.out.println ( "Welcome to the Payroll Program!" );
  10.  
  11. boolean stop = false;
  12. while ( !stop )
  13. {
  14. Scanner input = new Scanner ( System.in );
  15.  
  16. System.out.println();
  17. System.out.print ( "Enter Employee's Name or stop to exit program: " );
  18. String empName = input.nextLine();
  19.  
  20. if ( empName.equals ( "stop" ) )
  21. {
  22. System.out.println ( "Program Exited" );
  23. stop = true;
  24. }
  25. else
  26. {
  27. float hourlyRate;
  28. float hoursWorked;
  29. float weeklyPay;
  30.  
  31. System.out.print ( "Enter hourly rate: " );
  32. hourlyRate = input.nextFloat();
  33.  
  34. while ( hourlyRate <= 0 )
  35. {
  36. System.out.print ( "Hourly rate must be a positive number. " +
  37. "Please enter the hourly rate again: " );
  38. hourlyRate = input.nextFloat();
  39. }
  40.  
  41. System.out.print ( "Enter hours worked: " );
  42. hoursWorked = input.nextFloat();
  43. while ( hoursWorked <= 0 )
  44. {
  45. System.out.print ( "Hours worked must be a positive number. " +
  46. "Please re-enter hours worked: " );
  47. hoursWorked = input.nextFloat();
  48. }
  49.  
  50. weeklyPay = ( float ) hourlyRate * hoursWorked;
  51.  
  52. System.out.print ( empName );
  53. System.out.printf ( "'s weekly pay is: $%,.2f\n", weeklyPay );
  54.  
  55. }
  56. }
  57. System.out.println ( "Closing Payroll Program." );
  58. System.out.println();
  59. }
  60. }
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 40
Reputation: Coyboss is an unknown quantity at this point 
Solved Threads: 0
Coyboss Coyboss is offline Offline
Light Poster

Re: Need Help with Java for Payroll Program

 
0
  #5
Jan 15th, 2009
Thank you very muc for your assistance with this.

I really appreciate it!

COY
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC