//Payroll Program Part 2

package payrollprogrampart2;

/**
 *
 * @author Zach
 */
import java.util.Scanner;
public class PayrollProgramPart2 {
    public static void main(String args []) 

    {   System.out.println("Welcome to Zach's Payroll Program");

        Scanner input = new Scanner( System.in );

        String employeeName;

        System.out.print("What is the employee's name?");
        boolean stop = false;
        while (!stop)


        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;

        int number1;// hourly rate
        int number2;// total hours
        int sum;// total weekly pay

        System.out.print("Enter hourly rate:");
        number1 = input.nextInt();
        while (number1 <= 0)
        System.out.print( "Hourly rate must be a positive number." );
        number1 = input.nextInt ();

        System.out.print( "Enter total hours: " );
        number2 = input.nextInt();
        while (number2 <= 0)
        System.out.print("Hours worked must be a postive number.");
        number2 = input.nextInt();

        sum = number1 * number2;

        System.out.printf("Sum is %d\n",sum);
        }

Edited 3 Years Ago by Dani: Formatting fixed

I am new to programming and in netBeans it says that my last line is bad with the "reached end file while parsing" what does this meen? Thanks in advance. Also is there anything else wrong with it that you can see.

That error means that you reached the end of file without closing some brackets. You still need the main method bracket and the class bracket.

Regards

That error means that you reached the end of file without closing some brackets. You still need the main method bracket and the class bracket.

Regards

Thank you for your answer but where to they go? Im confused. Also is there anything else wrong with it. Thanks again.

Edited 4 Years Ago by zach1280: n/a

There are some issues also in your code.Because i fixed your code and compiled it.But when it starts to run only output the Welcome message.Therefore check the code again..And post the question also here.That'll be easy to understand the code..

Hi Zach!
I found out some mistakes in your code!
First, plz review your code:

while (!stop)


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;
int number1;// hourly rate
int number2;// total hours
int sum;// total weekly pay

System.out.print("Enter hourly rate:");
number1 = input.nextInt();
while (number1 <= 0)
System.out.print( "Hourly rate must be a positive number." );
number1 = input.nextInt ();

The 2 first line means you do this taks:

while (!stop)


System.out.print("Enter Employee's name or stop to exit program:");

forever! :)
You should use curly brace!
And, if you use curly braces like me:

while (!stop){
    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;

    int number1;// hourly rate
    int number2;// total hours
    int sum;// total weekly pay

    System.out.print("Enter hourly rate:");
    number1 = input.nextInt();
    while (number1 <= 0)
    System.out.print( "Hourly rate must be a positive number." );
    number1 = input.nextInt ();

    System.out.print( "Enter total hours: " );
    number2 = input.nextInt();
    while (number2 <= 0)
    System.out.print("Hours worked must be a postive number.");
    number2 = input.nextInt();

    sum = number1 * number2;

    System.out.printf("Sum is %d\n",sum);
    }
    }

program will not exit when you enter "stop"! You should using this statemetn:

if ( empName.equals ("stop")) System.exit(0);

I wanna notice you: when u use while loop, if there're more than 2 statements it must do if the condition's true, you should put the statements into a curly braces!
And dont forget to make sure that every "{" will ends with a "}"
----
Songokute

Yes be careful when you opens a curly brace.Definitely remember to close that brace as you opened that.

I'll tell you a good programming practice.That's when you opens a curly brace at the same time close it.After that write your code inside that.It won't be persuade to do mistakes.

Thanks everybody you all were a great help to me. hopfully I get a good grade. Thanks again.

This question has already been answered. Start a new discussion instead.