Create a non-GUI based Java application that calculates weekly pay for an employee. The application should display text that requests the user input the name of the employee, the hourly rate, and the number of hours worked for that week. The application should then print out the name of the employee and the weekly pay amount. In the printout, display the dollar symbol ($) to the left of the weekly pay amount and format the weekly pay amount to display currency.

This is what I have the compiler comes up with 3 errors line 15 states illegal start of type, line 84 states identifier expected and line 88 states class interface expected how do i fix these errors?

import java.util.Scanner; // program uses Scanner

public class Payroll3
{
 private String nameOfEmployee;

  public Payroll3( String name ) 
  { 
    nameOfEmployee = name;
  } // end constructor

     boolean exit = false; // this flag will stop the program

       // loop until user exits from program
       while ( !exit )
       {
         // create Scanner to obtain input from command window
         Scanner input = new Scanner( System.in );

         float HoursWorked; // input number of hours worked
         float PayRate; // input hourly pay rate
         float multiply; // multiply NumberHours with PayRate

         // clean input buffer
         String cleanInputBuffer = "";

         // input the employee's name
         System.out.print( "Enter the employee's name or exit to quit:" );
         String nameOfEmployee = input.nextLine(); // display employee's name

           if(nameOfEmployee.equals("exit"))
           {
              System.out.println( "End of Program.");
              exit = true;
           } // end if statement

           else
           {
              // user did not exit, so continue prompt
              System.out.print( "Enter number of hours worked:" ); // prompt for input
              HoursWorked = input.nextFloat(); // display number of hours worked
                while ( HoursWorked <= 0 ) // prompt the user to input a positive number
             {
                  System.out.print( "Number of hours worked must be a positive value." + "Please enter the number of hours worked again:" ); 
                  // prompt for a positive number
                  HoursWorked = input.nextFloat();
                } // end while

                //set hours worked
                public void setHoursWorked( float hours )
                {
                   HoursWorked = HoursWorked;
                }
                public float getHoursWorked() // method get hours worked
                {
                   return HoursWorked;
                }
                     System.out.print( "Enter hourly pay rate: " ); // prompt for input
                     PayRate = input.nextFloat(); // display hourly rate
                     while ( PayRate <= 0 ) // prompt the user to input a positive number
                     {
                     System.out.print( "Pay Rate must be a positive value." + "Enter hourly pay rate: " ); // prompt for a positive number
                     PayRate = input.nextFloat(); // display hourly rate
                     } // end while
                   public void setPayRate( float PayRate ) // method set pay rate
                   {
                     PayRate = PayRate;
                   }
                   public float getPayRate() // method get pay rate
                   {
                     return PayRate;
                   }
                        public float calculateWeeklyPay()
                      {
                        return multiply = HoursWorked * PayRate; //calculate weekly pay
                      }

                       System.out.print( "Total weekly pay is $%.2f\n", multiply); // display weekly pay
                       cleanInputBuffer = input.nextLine();
            } // end else statement

                     System.out.println(); // inserts a blank line

        } // end while

  } // end main

} // end class Payroll3

and

import java.util.Scanner;

public class TestPayroll3 
 { // start Payroll3 

  public static void main( String args[]) 
  { 
  Scanner input = new Scanner( System.in ); 


    TestPayroll3 myEmployee = new TestPayroll3(); 


    System.out.printf("Enter the employee's name or exit to quit:"); 


         System.out.print( "Enter hourly pay rate: " ); 
         myEmployee.setpayrate(input.nextDouble()); 


         System.out.print( "Please enter the number of hours worked again:" ); 
         myEmployee.sethoursworked(input.nextDouble()); 


         System.out.printf("Employee earned " + myEmployee.calculateweeklypay() ); 


  } // end main
 } // end Payroll3

Hi,

Class definition should contain only variable and method declarations(and or definitions).

Your while loops should be with in some function.

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.