| | |
Need Help with Java for Payroll Program
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 40
Reputation:
Solved Threads: 0
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
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
Java Syntax (Toggle Plain Text)
package employee_pay; // Payroll program calculates employee's weekly pay. import java.util.Scanner; public class pay{ 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); { Scanner input = new Scanner(System.in ); System.out.println(); System.out.print( "Enter Employee's Name or stop to exit program: " ); String empName = input.nextLine(); 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 Pay
hahaha this is a really unfortunate error:
notice the semicolon (hence an infinite loop of empty statement)
java Syntax (Toggle Plain Text)
while (!stop);{
notice the semicolon (hence an infinite loop of empty statement)
Delete it.
Also consider formatting your code properly:
Also consider formatting your code properly:
Java Syntax (Toggle Plain Text)
package employee_pay; import java.util.Scanner; public class pay { public static void main ( String args[] ) { System.out.println ( "Welcome to the Payroll Program!" ); boolean stop = false; while ( !stop ) { Scanner input = new Scanner ( System.in ); System.out.println(); System.out.print ( "Enter Employee's Name or stop to exit program: " ); String empName = input.nextLine(); if ( empName.equals ( "stop" ) ) { System.out.println ( "Program Exited" ); stop = true; } else { float hourlyRate; float hoursWorked; float weeklyPay; System.out.print ( "Enter hourly rate: " ); hourlyRate = input.nextFloat(); while ( hourlyRate <= 0 ) { System.out.print ( "Hourly rate must be a positive number. " + "Please enter the hourly rate again: " ); hourlyRate = input.nextFloat(); } System.out.print ( "Enter hours worked: " ); hoursWorked = input.nextFloat(); while ( hoursWorked <= 0 ) { System.out.print ( "Hours worked must be a positive number. " + "Please re-enter hours worked: " ); hoursWorked = input.nextFloat(); } weeklyPay = ( float ) hourlyRate * hoursWorked; System.out.print ( empName ); System.out.printf ( "'s weekly pay is: $%,.2f\n", weeklyPay ); } } System.out.println ( "Closing Payroll Program." ); System.out.println(); } }
*Voted best profile in the world*
![]() |
Similar Threads
- Need help with Java Payroll Program Part 2 (Java)
- Payroll Program (Java)
- Payroll program confusion (Java)
- Payroll Program (Java)
- JAVA Beginner (Java)
- Java Programming (Java)
- trouble executing java archive (Java)
Other Threads in the Java Forum
- Previous Thread: very basic sun tutorial base question
- Next Thread: Lookup Table
| Thread Tools | Search this Thread |
account android api applet application array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) chat class classes client code columns component database designadrawingapplicationusingjavajslider draw eclipse error errors exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source plazmic print problem program programming project property recursion ria scanner search server set smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree webservices windows






