-
payroll program 2
having problems with my code i can not get it to run it says I have 2 errors but the errors don't make any sense. Does anyone know what I'm doing wrong.
Heres my code.
/*
*
* Payroll Program - PayrollProgram Class
* Axia College - University of Phoenix
* IT 215 - Java Programming
*
*/
import java.util.Scanner; // Program uses class Scanner to accept user input
import java.text.NumberFormat; // Program Uses Class NumberFormat to format number output
import java.util.Locale; // Program Needs to Use U.S. Currency
public class PayrollProgram
{
public static void main(String[] args)
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
// Set Currency to U.S. Dollars
NumberFormat currency = NumberFormat.getCurrencyInstance(Locale.US);
// Variable Specifications
String employeeName; // Placeholder for employee name
float hoursWorked; // Number of hours worked in a week
float hourlyRate; // Employee's hourly rate
float weeklyPay; // Weekly pay as product of hours worked and the hourly rate
// Show Program Welcome Message
System.out.println( ); // Show an Empty Line
System.out.println( "Welcome to the Payroll Program!!!"); // Show Welcome Message
System.out.println( );
while(true) // continuous loop --> loops until "stop" is entered as the employeeName
{
// Show an Empty Line
System.out.println( );
// Prompt for Employee Name
System.out.print( "Enter employee name (or STOP to exit the program): " ); // prompt message
employeeName = input.nextLine(); // read the employee's name
// Check to See if the User Entered "stop" to End the Program
if ( employeeName.equalsIgnoreCase("stop") )
{
break; // Break Out of While Loop
do
{
// Prompt for Employee's Hourly Pay Rate
System.out.print( "Enter hourly rate: " ); // prompt message
hourlyRate = input.nextFloat(); // read the employee's hourly pay rate
if (hourlyRate < 0)
{
System.out.println( "ERROR: The hourly rate must be a positive number." ); // show error message
}
} while ( hourlyRate < 0 ); // end do while statement
do
{
// Prompt for Number of Hours Worked
System.out.print( "Enter hours worked: " ); // prompt message
hoursWorked = input.nextFloat(); // read number of hours worked in a week
if (hoursWorked < 0)
{
System.out.println( "ERROR: The number of hours worked must be a positive number." ); // show error message
}
} while ( hoursWorked < 0 ); // end do while statement
// Calculate Employee's Weekly Pay
weeklyPay = hourlyRate * hoursWorked;
// Output program results to the display
System.out.println( ); // Show an Empty Line
System.out.println( "Employee Name: " + employeeName);
System.out.println( "Employee's Weekly Pay = " + currency.format(weeklyPay) );
input.nextLine(); // Need this to remove carriage return from input queue
} // end while statement
// Show Program Exit Message
System.out.println( ); // Show an Empty Line
System.out.println( "Now exiting the Payroll Program."); // Show Exit Message
System.out.println( ); // Show an Empty Line
} //end While statement
-
Please copy and paste your error messages for us to see. We can't read minds, so any help you can give us to help you will be nice.
-
Please use code tags when posting code.
...and your errors are (in full, indicating the lines they occur on)?
You can't expect people to copy and paste the code and try and compile it themselves...
-
sorry about that i forgot to put them in
C:\Users\Josh\Documents\NetBeansProjects\Payroll Program Part 2\src\PayrollProgram.java:118: '}' expected
1 error
C:\Users\Josh\Documents\NetBeansProjects\Payroll Program Part 2\nbproject\build-impl.xml:363: The following error occurred while executing this line:
C:\Users\Josh\Documents\NetBeansProjects\Payroll Program Part 2\nbproject\build-impl.xml:168: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)
thanks again for the help
-
Well you're missing a } somewhere. Whats line 118?
-
You need to show us where these lines are.
As I said, you can't expect us to copy and paste this code into an IDE.
-
well I'm new to this form and still trying to figure it out so if you could help because i do not know how to tag my code to make it easier for you to help me
-
If you quote my earlier post you'll see the code tags.
-
[code][/code] Is the tags you want to use. Putting your code in between them.
Also, if you tell us what line 118 is we might be able to help you out a little bit more.
-
here you go
Code:
import java.util.Scanner; // Program uses class Scanner to accept user input
import java.text.NumberFormat; // Program Uses Class NumberFormat to format number output
import java.util.Locale; // Program Needs to Use U.S. Currency
public class PayrollProgram
{
public static void main(String[] args)
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
// Set Currency to U.S. Dollars
NumberFormat currency = NumberFormat.getCurrencyInstance(Locale.US);
// Variable Specifications
String employeeName; // Placeholder for employee name
float hoursWorked; // Number of hours worked in a week
float hourlyRate; // Employee's hourly rate
float weeklyPay; // Weekly pay as product of hours worked and the hourly rate
// Show Program Welcome Message
System.out.println( ); // Show an Empty Line
System.out.println( "Welcome to the Payroll Program!!!"); // Show Welcome Message
System.out.println( );
while(true) // continuous loop --> loops until "stop" is entered as the employeeName
{
// Show an Empty Line
System.out.println( );
// Prompt for Employee Name
System.out.print( "Enter employee name (or STOP to exit the program): " ); // prompt message
employeeName = input.nextLine(); // read the employee's name
// Check to See if the User Entered "stop" to End the Program
if ( employeeName.equalsIgnoreCase("stop") )
{
break; // Break Out of While Loop
[B][I][COLOR="DarkOrange"] do [/COLOR][/I][/B]
{
// Prompt for Employee's Hourly Pay Rate
System.out.print( "Enter hourly rate: " ); // prompt message
hourlyRate = input.nextFloat(); // read the employee's hourly pay rate
if (hourlyRate < 0)
{
System.out.println( "ERROR: The hourly rate must be a positive number." ); // show error message
}
} while ( hourlyRate < 0 ); // end do while statement
do
{
// Prompt for Number of Hours Worked
System.out.print( "Enter hours worked: " ); // prompt message
hoursWorked = input.nextFloat(); // read number of hours worked in a week
if (hoursWorked < 0)
{
System.out.println( "ERROR: The number of hours worked must be a positive number." ); // show error message
}
} while ( hoursWorked < 0 ); // end do while statement
// Calculate Employee's Weekly Pay
weeklyPay = hourlyRate * hoursWorked;
// Output program results to the display
System.out.println( ); // Show an Empty Line
System.out.println( "Employee Name: " + employeeName);
System.out.println( "Employee's Weekly Pay = " + currency.format(weeklyPay) );
input.nextLine(); // Need this to remove carriage return from input queue
} // end while statement
// Show Program Exit Message
System.out.println( ); // Show an Empty Line
System.out.println( "Now exiting the Payroll Program."); // Show Exit Message
System.out.println( ); // Show an Empty Line
[COLOR="Red"][B]}[/B][/COLOR]
-
The end brace has to have a / in front of code, [/code]
Also, any visual indication of the error line is fine, bold it, italicize, color, etc.
-
line 59 is a do statement and it say's its not a reachable statement
Line 117 is the last line of my code it does not make any sense because my teacher made the code and we piece it together, and he said there were no errors. It says reached end of
file while parsing
thanks
-
Code:
System.out.println( ); // Show an Empty Line
System.out.println( "Now exiting the Payroll Program."); // Show Exit Message
System.out.println( ); // Show an Empty Line
} // end of main method
// no closing bracket for the class
If this is you actuall code then you are missing a bracket at the end. Otherwise you have a mis-matched brackets somewhere else in your code. Don't make us go through your code line by line to find it. This is a job that you have to do.
-
As for the do error:
Code:
if ( employeeName.equalsIgnoreCase("stop") )
{
[B] break; // Break Out of While Loop[/B]
do
You will always exit the outer while loop before getting to the do command.
So, if this is the code that was working for yout teacher, then you've copied it incorrectly somehow.