0

Could some one look at this program and let me know if the Scanner object and variables are defined and defined correctly? And make suggestions on how to fix it if it is wrong. I also want to know if my validations are correct for employee, hours, and rate are correct, if not suggestions on how to fix them would be extremely helpful. I feel a little lost on this java programming stuff even with all the text and websites that I have read through.

import java.util.Scanner; // scanner for input

public class Payrollprogram

{
   // main method begin program execution
    public static void main( String args[] )
      {
        // scanner to obtain user input 
        Scanner input = new Scanner( System.in );
      
           // scanner employee object
             {
                Employee = newEmployee(name,hours,rate); 
             }
      }

         //display welcome message for user
         public void displayMessage()
            {
              System.out.printf( "Welcome to payroll for\n%s!\n\n",
              getEmployeeName() );
            } // end displayMessage method

         //get employee name
            {
              System.out.println( "Enter employee name: " );
            }

               {
                 employeeName = input.nextLine();
                 while (employee.equals(""))
               {
                 System.out.print( "Enter proper employee name: " );
                 employee = Input.nextString();
                 // continue
               }

                  if(employee==stop)
                    {
                      System.exit();
                    }
            } // end get employee name



         // hours worked
            {
              do
              {
                System.out.print( "How many hours did " + employee + " work? ");
                hours = Input.nextDouble();
                if(hours < 0)
                  {
                    System.out.print( "Enter proper number of hours: ");
                    hours = Input.nextDouble();
                  }
                   hours_valid = true;
               } while (hours < 0);
             }// end hours worked class



         // pay rate 
            {
              do
              {
                System.out.print( "How much does " + employee + " make per hour? ");
                rate = Input.nextDouble();
                if (rate < 0)
                  {
                    System.out.print( "Enter proper number for rate: ");
                    rate = Input.nextDouble();
                  }
                   rate_valid = true;
              } while (hours < 0); 
             }// end pay rate class



        // calculate pay total
           {
             pay = rate * hours;
             NumberFormat fmt = NumberFormat.getCurrencyInstance();
             System.out.println("\n" + employee + " worked for " + hours
             + " hours at " + fmt.format(rate) + "/hr; paycheck = "
             + fmt.format(pay));
           }



} // end Payroll class

I am very unsure of my work because this is my first program. Please help.

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Easter Bunny
0

ok. you haven't told the program you are going to use all those variables that you have in there. you need to start off by listing your variables:

import java.util.Scanner; // scanner for input

public class Payrollprogram
{
    int id, pay, value... etc;   //list the integers that the program is going to be using
    String name, surname, telephone... etc; //list the Strings that the program is going to be using

    // main method begin program execution
    public static void main( String args[] )
    {
         .
         .
         .
    }
}

then you need to use the scanner to read in the stuff that the user will be typing.

is this perhaps a project? did you start off with the "hello world" program? :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.