This code has gven me more problems than it is probably worth. Can anyone help me please?

package payrollprogram2;

import java.util.Scanner;

public class PayrollProgram2 { //begin class

    public static void main(String[] args) { //begin main

        System.out.println("Welcome to the Payroll Program");
        //output Welcome to the Payroll Program
        Scanner input = new Scanner(System.in);
        // gets scanner ready for input

        boolean stop = false; // this will allow looping until the user enters the word stop
        double HourlyRate = 0;  //HourlyRate is integer
        double WorkedHours = 0; //WorkedHours is integer
        double BiweeklyPay = 0;   // BiweeklyPay is integer and sum of HourlyRate and WorkedHours
        String name; // Employees name

        System.out.println("Enter the worker's name (Or stop to exit the program): ");
        name = input.nextLine(); // this is going to set the name of the worker

                while (true) {
            if (name.equals("stop")) {
                System.out.println("Good-Bye");
                stop = true;
           }//end if

            else {

                System.out.println("Enter the number of hours worked by this person for the last two weeks: "); // this is going to allow the user to put the number of hours the person worked
                WorkedHours = input.nextDouble();  // this is going to capture the number of hours that the person worked for the last two weeks

            if (WorkedHours <=0)
            {
                System.out.println("Please re-enter a positive number");
                // This will allow only positive numbers to be entered

                System.out.println("Please enter the number of hours worked by this person for the last two weeks: ");// allows user to input a positive number
            } // end if

            else

            System.out.printf("Enter the hourly rate for this worker: $", HourlyRate); // this is going to allow the user to put in the hourly rate for the worker
            HourlyRate = input.nextDouble(); // this is going to capture the hourly rate for the worker

              if (HourlyRate <=0)
            {
                System.out.println("Please re-enter a positive amount");
                // This will allow only positive numbers to be entered

                System.out.printf("Enter the hourly rate for this worker: $", HourlyRate);// allows user to input a positive number
            } // end if

              else
            BiweeklyPay = HourlyRate * WorkedHours; //this is going to multiply the hourly rate by the number of hours worked


            System.out.printf("%s will earn $%.2f %n", name, BiweeklyPay); // this is going to output the worker's name and how much they earned for the last two weeks

            } // end else
        } // end while
}//end main

}//end class

Recommended Answers

All 2 Replies

Maybe if we knew what "problems" you are talking about.

Your code would be easier to read if you removed all the redundant comments. You can assume that anyone reading your code understands Java, so there's no point having a comment that just explains what the previous statement means - eg

System.out.println("Welcome to the Payroll Program");
//output Welcome to the Payroll Program
Scanner input = new Scanner(System.in);
// gets scanner ready for input

You should also have a look at the comments that are downright wrong, eg

double HourlyRate = 0; //HourlyRate is integer
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.