Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 98,764 Java Programmers for FREE!. Ask your question and get quick answers from Dream.In.Code experts. There are 1,044 online right now! We're the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Java Expert

Register to Make This Box Go Away!


Payroll program part 3

 
Reply to this topicStart new topic

Payroll program part 3

cmymazda
post 3 Sep, 2007 - 07:15 PM
Post #1


New D.I.C Head

*
Joined: 27 Aug, 2007
Posts: 13


My Contributions


Please help me with this error C:\IT315\Payroll 3\Payroll 3.java:6: '{' expected
public class Payroll 3 {

Here is my code below.

CODE
//Payroll 3
import java.util.Scanner;

public class Payroll 3 {

  
    // main begin Java application
    public static void main (String []args) {
           Scanner input = new Scanner(System.in);
           String name; // employee name
          
           if (name.getName().equals("Stop"))
                {      
                   System.out.println("Stop Entered,");
                   //stop = true;
                   Quit ();
                  }// end if
                  else
                  System.out.print ("\nEnter Employee Name: ");//prompt for name
                  name.setName(input.nextLine());// get name
                  if (name.getName().equals ("stop"));
                  {
                   System.out.println("Stop Entered,");
                   //stop = true;
                   Break ();
                  
                   // Loop until user types "stop" as name: while (!stop)
                  }// end if
                  
                                            
                  System.out.print ("Enter Employee payRate: $"); //prompt
                  name.setpayRate = (input.nextDouble());
                  if (name.getpayRate() <=0)  
                  {
                           System.out.println ("Invalid amount, setpayRate must be positive");
                           System.out.print ("Please enter valid payrate: $");
                           name.setpayRate = (input.nextDouble());
                           // Loop until valid number is entered for payrate: while (setpayRate < 0.0)
                    } // end if
                   System.out.print ("Enter number hours worked: ");
                   name.sethoursWorked = (input.nextDouble());
                   if (name.gethoursWorked() <=0)   {
                         System.out.println ("Invalid amount, hoursWorked must be positive");
                         System.out.print ("Please enter valid hourWorked: ");
                         name.sethoursWorked = (input.nextDouble());
                         // Loop until valid number of hours is entered: while (name.sethourWorked < 0.0)
                    }//end if
    
                                
                  System.out.printf(" %s's weekly earned pay is: $%.2f\n", name, earnedPay);
                  Quit();
  
      }// end  method main
  
   }//end class Payroll 3

//  Class Employee
class Employee

{
                 String name;
                 private double hourlyRate;
                 private double hourWorked;
                 public Employee ()
                   {
                       //implicit call to object constructor occurs here
                        name = "";
                        payRate = 0.0;
                        hoursWorked = 0.0;
                     }
                 // Three argument initialization constructor
              public Employee(String employeenameIn, double hourlyRateInDollarsIn, double hoursWorkedInWeekIn)
                    {
                       //implicit call to object constructor occurs here
                           name = NameIn;
                           hourlyRate = hourlyWageInDollarsIn;
                           hoursWorked = hoursWorkedInWeekIn;
                    } // end three argument intialization constructor
                   public void name (string name) {
                           this.name = name;
                    }
                    String getName ()
                    {
                            return name;
                     }
                     public void setpayRate (double payRate)
                    {
                            this.payRate = payRate;
                     }
                     public double getpayRate ()
                     {
                             return payRate;
                     }
                     public void sethoursWorked ()
                     {
                             this.hoursWorked = hours;
                      }
                     public double gethoursWorked ()
                      {
                              return hours;
                       }
                     public double getearnedPay ()
                       {
                              return (payRate * hoursWorked);
                       }
    }// end class Employee
edit: PLEASE USE CODE TAGS

This post has been edited by PennyBoki: 3 Sep, 2007 - 07:25 PM
User is offlineProfile CardPM

Go to the top of the page


PennyBoki
post 3 Sep, 2007 - 07:37 PM
Post #2


system("revolution");

Group Icon
Joined: 11 Dec, 2006
Posts: 2,009



Thanked 1 times

Dream Kudos: 500

Expert In: Java,C++,C

My Contributions


The name of your class should be Payroll3 instead of Payroll 3, same withe the .java file name
User is offlineProfile CardPM

Go to the top of the page

cmymazda
post 3 Sep, 2007 - 09:06 PM
Post #3


New D.I.C Head

*
Joined: 27 Aug, 2007
Posts: 13


My Contributions


QUOTE(PennyBoki @ 3 Sep, 2007 - 07:37 PM) *

The name of your class should be Payroll3 instead of Payroll 3, same withe the .java file name



Hello PennyBoki,

First, thanks for your help. When I made the change I now have 27 errors... what did I do wrong?

C:\IT315\Payroll 3\Payroll 3.java:6: class Payroll3 is public, should be declared in a file named Payroll3.java
public class Payroll3 {
^
C:\IT315\Payroll 3\Payroll 3.java:81: cannot find symbol
symbol : class string
location: class Employee
public void name (string name) {
^
C:\IT315\Payroll 3\Payroll 3.java:14: cannot find symbol
symbol : method getName()
location: class java.lang.String
if (name.getName().equals("Stop"))
^
C:\IT315\Payroll 3\Payroll 3.java:18: cannot find symbol
symbol : method Quit()
location: class Payroll3
Quit ();
^
C:\IT315\Payroll 3\Payroll 3.java:22: cannot find symbol
symbol : method setName(java.lang.String)
location: class java.lang.String
name.setName(input.nextLine());// get name
^
C:\IT315\Payroll 3\Payroll 3.java:23: cannot find symbol
symbol : method getName()
location: class java.lang.String
if (name.getName().equals ("stop"));
^
C:\IT315\Payroll 3\Payroll 3.java:27: cannot find symbol
symbol : method Break()
location: class Payroll3
Break () ;
^
C:\IT315\Payroll 3\Payroll 3.java:34: cannot find symbol
symbol : variable setpayRate
location: class java.lang.String
name.setpayRate = (input.nextDouble()) ;
^
C:\IT315\Payroll 3\Payroll 3.java:35: cannot find symbol
symbol : method getpayRate()
location: class java.lang.String
if (name.getpayRate() <=0)
^
C:\IT315\Payroll 3\Payroll 3.java:39: cannot find symbol
symbol : variable setpayRate
location: class java.lang.String
name.setpayRate = (input.nextDouble());
^
C:\IT315\Payroll 3\Payroll 3.java:43: cannot find symbol
symbol : variable sethoursWorked
location: class java.lang.String
name.sethoursWorked = (input.nextDouble()) ;
^
C:\IT315\Payroll 3\Payroll 3.java:44: cannot find symbol
symbol : method gethoursWorked()
location: class java.lang.String
if (name.gethoursWorked() <=0) {
^
C:\IT315\Payroll 3\Payroll 3.java:47: cannot find symbol
symbol : variable sethoursWorked
location: class java.lang.String
name.sethoursWorked = (input.nextDouble()) ;
^
C:\IT315\Payroll 3\Payroll 3.java:52: cannot find symbol
symbol : variable earnedPay
location: class Payroll3
System.out.printf(" %s's weekly earned pay is: $%.2f\n", name, earnedPay) ;
^
C:\IT315\Payroll 3\Payroll 3.java:53: cannot find symbol
symbol : method Quit()
location: class Payroll3
Quit();
^
C:\IT315\Payroll 3\Payroll 3.java:70: cannot find symbol
symbol : variable payRate
location: class Employee
payRate = 0.0 ;
^
C:\IT315\Payroll 3\Payroll 3.java:71: cannot find symbol
symbol : variable hoursWorked
location: class Employee
hoursWorked = 0.0 ;
^
C:\IT315\Payroll 3\Payroll 3.java:77: cannot find symbol
symbol : variable NameIn
location: class Employee
name = NameIn ;
^
C:\IT315\Payroll 3\Payroll 3.java:78: cannot find symbol
symbol : variable hourlyWageInDollarsIn
location: class Employee
hourlyRate = hourlyWageInDollarsIn ;
^
C:\IT315\Payroll 3\Payroll 3.java:79: cannot find symbol
symbol : variable hoursWorked
location: class Employee
hoursWorked = hoursWorkedInWeekIn ;
^
C:\IT315\Payroll 3\Payroll 3.java:90: cannot find symbol
symbol : variable payRate
location: class Employee
this.payRate = payRate;
^
C:\IT315\Payroll 3\Payroll 3.java:94: cannot find symbol
symbol : variable payRate
location: class Employee
return payRate ;
^
C:\IT315\Payroll 3\Payroll 3.java:98: cannot find symbol
symbol : variable hoursWorked
location: class Employee
this.hoursWorked = hours ;
^
C:\IT315\Payroll 3\Payroll 3.java:98: cannot find symbol
symbol : variable hours
location: class Employee
this.hoursWorked = hours ;
^
C:\IT315\Payroll 3\Payroll 3.java:102: cannot find symbol
symbol : variable hours
location: class Employee
return hours;
^
C:\IT315\Payroll 3\Payroll 3.java:106: cannot find symbol
symbol : variable payRate
location: class Employee
return (payRate * hoursWorked) ;
^
C:\IT315\Payroll 3\Payroll 3.java:106: cannot find symbol
symbol : variable hoursWorked
location: class Employee
return (payRate * hoursWorked) ;
^
27 errors
Exit code: 1
There were errors
User is offlineProfile CardPM

Go to the top of the page

PennyBoki
post 3 Sep, 2007 - 09:56 PM
Post #4


system("revolution");

Group Icon
Joined: 11 Dec, 2006
Posts: 2,009



Thanked 1 times

Dream Kudos: 500

Expert In: Java,C++,C

My Contributions


First as I said create a new file called Payroll3.java and the name of your class should be Payroll3.
User is offlineProfile CardPM

Go to the top of the page

cmymazda
post 3 Sep, 2007 - 10:25 PM
Post #5


New D.I.C Head

*
Joined: 27 Aug, 2007
Posts: 13


My Contributions


QUOTE(PennyBoki @ 3 Sep, 2007 - 09:56 PM) *

First as I said create a new file called Payroll3.java and the name of your class should be Payroll3.



PennyBoki,

I did that and have fixed all of the errors but 1
C:\IT315\Payroll 3\Payroll3.java:50: class, interface, or enum expected
} //end class Payroll3
here is the code
CODE
//Payroll3
import java.util.Scanner;

public class Payroll3 {

  
    // main begin Java application
    public static void main (String []args) {
            Employee emp = new Employee();
           Scanner input = new Scanner(System.in);
                      
           double payRate;
           double hoursWorked;
           double earnedPay;
          
           while (true)
              System.out.println("\nEnter Employee Name :");
              emp.setName(input.next());
                
           if (!emp.getName().equals("Stop"))
                {    
                                      
                            
                                        
                  System.out.print ("Enter Employee payRate: $"); //prompt
                  emp.setpayRate = (input.nextDouble());
                  while (emp.getpayRate() <=0)  
                  {
                           System.out.println ("Invalid amount, setpayRate must be positive");
                           System.out.print ("Please enter valid payrate: $");
                           emp.setpayRate = (input.nextDouble());
                           // Loop until valid number is entered for payrate: while (setpayRate < 0.0)
                    } // end while
                   System.out.print ("Enter number hours worked: ");
                   emp.sethoursWorked = (input.nextDouble());
                   while(emp.gethoursWorked() <=0)   {
                         System.out.println ("Invalid amount, hoursWorked must be positive");
                         System.out.print ("Please enter valid hourWorked: ");
                         emp.sethoursWorked = (input.nextDouble());
                        }
                        System.out.printf("%s's weekly earned pay is: $%.2f\n", name, earnedPay);
                       }
                       else break;
                      }
                                          
                    }// end main
                    
   } //end class Payroll3                    
    
   }
//  Class Employee
class Employee

{
                 private String name;
                 private double hourlyRate;
                 private double hourWorked;
                 public Employee ()
                
                   {
                       //implicit call to object constructor occurs here
                        name = "";
                        payRate = 0.0;
                        hoursWorked = 0.0;
                     }
                 // Three argument initialization constructor
              public Employee(String employeenameIn, double hourlyRateInDollarsIn, double hoursWorkedInWeekIn)
                    {
                       //implicit call to object constructor occurs here
                           name = NameIn;
                           hourlyRate = hourlyWageInDollarsIn;
                           hoursWorked = hoursWorkedInWeekIn;
                    } // end three argument intialization constructor
                   public void name (String name) {
                           this.name = name;
                    }
                    String getName ()
                    {
                            return name;
                     }
                    
                     public void setpayRate (double payRate)
                    {
                            this.payRate = payRate;
                     }
                     public double getpayRate ()
                     {
                             return payRate;
                     }
                     public void sethoursWorked ()
                     {
                             this.hoursWorked = hours;
                      }
                     public double gethoursWorked ()
                      {
                              return hours;
                       }
                     public double getearnedPay ()
                       {
                              return (payRate * hoursWorked);
                       }
    }// end class Employee

edit: please use code tags

This post has been edited by PennyBoki: 4 Sep, 2007 - 01:30 AM
User is offlineProfile CardPM

Go to the top of the page

PennyBoki
post 4 Sep, 2007 - 01:48 AM
Post #6


system("revolution");

Group Icon
Joined: 11 Dec, 2006
Posts: 2,009



Thanked 1 times

Dream Kudos: 500

Expert In: Java,C++,C

My Contributions


No, no, no my friend, at that moment yes the compiler shows one error but after removing that error there were many many many many many many ... many errors.

I managed to get it compile and then run, but there were other logical errors I would say in respect of what your program should do.

However I am not going to give you the code, because you had too many errors, so I don't think you'll be patient enough to try to learn by comparing. I know I wouldn't be. So I'm thinking how is the best way to try to show you what have you done, and the best I can do is give you advise: to get back on the drawing board, I mean back on the basics, there were so many basic errors, like assigning value to a function with the assignment operator, using different names for variables, working with if/else statements and while loops.

There are snippets and tutorials here that you can pick up valuable hints and tips.

With all do respect, that is my advice to you.
Sincerely PennyBoki
User is offlineProfile CardPM

Go to the top of the page

Trebuntou
post 4 Sep, 2007 - 06:36 AM
Post #7


New D.I.C Head

*
Joined: 4 Sep, 2007
Posts: 8


My Contributions


QUOTE(cmymazda @ 3 Sep, 2007 - 07:15 PM) *

Please help me with this error C:\IT315\Payroll 3\Payroll 3.java:6: '{' expected
public class Payroll3 {

Here is my code below.

CODE
//Payroll 3
import java.util.Scanner;

public class Payroll3 {

  
    // main begin Java application
    public static void main (String []args) {
           Scanner input = new Scanner(System.in);
           String name; // employee name
          
           if (name.getName().equals("Stop"))
                {      
                   System.out.println("Stop Entered,");
                   //stop = true;
                   Quit ();
                  }// end if
                  else
                  System.out.print ("\nEnter Employee Name: ");//prompt for name
                  name.setName(input.nextLine());// get name
                  if (name.getName().equals ("stop"));
                  {
                   System.out.println("Stop Entered,");
                   //stop = true;
                   Break ();
                  
                   // Loop until user types "stop" as name: while (!stop)
                  }// end if
                  
                                            
                  System.out.print ("Enter Employee payRate: $"); //prompt
                  name.setpayRate = (input.nextDouble());
                  if (name.getpayRate() <=0)  
                  {
                           System.out.println ("Invalid amount, setpayRate must be positive");
                           System.out.print ("Please enter valid payrate: $");
                           name.setpayRate = (input.nextDouble());
                           // Loop until valid number is entered for payrate: while (setpayRate < 0.0)
                    } // end if
                   System.out.print ("Enter number hours worked: ");
                   name.sethoursWorked = (input.nextDouble());
                   if (name.gethoursWorked() <=0)   {
                         System.out.println ("Invalid amount, hoursWorked must be positive");
                         System.out.print ("Please enter valid hourWorked: ");
                         name.sethoursWorked = (input.nextDouble());
                         // Loop until valid number of hours is entered: while (name.sethourWorked < 0.0)
                    }//end if
    
                                
                  System.out.printf(" %s's weekly earned pay is: $%.2f\n", name, earnedPay);
                  Quit();
  
      }// end  method main
  
   }//end class Payroll 3

//  Class Employee
class Employee

{
                 String name;
                 private double hourlyRate;
                 private double hourWorked;
                 public Employee ()
                   {
                       //implicit call to object constructor occurs here
                        name = "";
                        payRate = 0.0;
                        hoursWorked = 0.0;
                     }
                 // Three argument initialization constructor
              public Employee(String employeenameIn, double hourlyRateInDollarsIn, double hoursWorkedInWeekIn)
                    {
                       //implicit call to object constructor occurs here
                           name = NameIn;
                           hourlyRate = hourlyWageInDollarsIn;
                           hoursWorked = hoursWorkedInWeekIn;
                    } // end three argument intialization constructor
                   public void name (string name) {
                           this.name = name;
                    }
                    String getName ()
                    {
                            return name;
                     }
                     public void setpayRate (double payRate)
                    {
                            this.payRate = payRate;
                     }
                     public double getpayRate ()
                     {
                             return payRate;
                     }
                     public void sethoursWorked ()
                     {
                             this.hoursWorked = hours;
                      }
                     public double gethoursWorked ()
                      {
                              return hours;
                       }
                     public double getearnedPay ()
                       {
                              return (payRate * hoursWorked);
                       }
    }// end class Employee
edit: PLEASE USE CODE TAGS

// i remove the space from your class name payroll 3
// try not to use that instead use Class name payroll3
// thanks from your friend robert

User is offlineProfile CardPM

Go to the top of the page

PennyBoki
post 4 Sep, 2007 - 09:05 AM
Post #8


system("revolution");

Group Icon
Joined: 11 Dec, 2006
Posts: 2,009



Thanked 1 times

Dream Kudos: 500

Expert In: Java,C++,C

My Contributions


Hi Trebuntou, you were saying...
User is offlineProfile CardPM

Go to the top of the page

cmymazda
post 4 Sep, 2007 - 04:12 PM
Post #9


New D.I.C Head

*
Joined: 27 Aug, 2007
Posts: 13


My Contributions


QUOTE(PennyBoki @ 4 Sep, 2007 - 01:48 AM) *

No, no, no my friend, at that moment yes the compiler shows one error but after removing that error there were many many many many many many ... many errors.

I managed to get it compile and then run, but there were other logical errors I would say in respect of what your program should do.

However I am not going to give you the code, because you had too many errors, so I don't think you'll be patient enough to try to learn by comparing. I know I wouldn't be. So I'm thinking how is the best way to try to show you what have you done, and the best I can do is give you advise: to get back on the drawing board, I mean back on the basics, there were so many basic errors, like assigning value to a function with the assignment operator, using different names for variables, working with if/else statements and while loops.

There are snippets and tutorials here that you can pick up valuable hints and tips.

With all do respect, that is my advice to you.
Sincerely PennyBoki

User is offlineProfile CardPM

Go to the top of the page

cmymazda
post 4 Sep, 2007 - 04:23 PM
Post #10


New D.I.C Head

*
Joined: 27 Aug, 2007
Posts: 13


My Contributions


QUOTE(PennyBoki @ 4 Sep, 2007 - 01:48 AM) *

No, no, no my friend, at that moment yes the compiler shows one error but after removing that error there were many many many many many many ... many errors.

I managed to get it compile and then run, but there were other logical errors I would say in respect of what your program should do.

However I am not going to give you the code, because you had too many errors, so I don't think you'll be patient enough to try to learn by comparing. I know I wouldn't be. So I'm thinking how is the best way to try to show you what have you done, and the best I can do is give you advise: to get back on the drawing board, I mean back on the basics, there were so many basic errors, like assigning value to a function with the assignment operator, using different names for variables, working with if/else statements and while loops.

There are snippets and tutorials here that you can pick up valuable hints and tips.

With all do respect, that is my advice to you.
Sincerely PennyBoki




Okay PennyBoki well I think now that i have all the errors cleaned up but I still not getting it to satisfy the requirements of the assignment which are:

Modify the Payroll Program so that it uses a class to store and retrieve the employee's name,
the hourly rate, and the number of hours worked. Use a constructor to initialize the employee
information, and a method within that class to calculate the weekly pay. Once stop is entered
as the employee name, the application should terminate. Make sure the program maintains all
the functionality required in previous assignments and your source code is readable and well
documented.

Here is my code:
CODE


//Payroll3
import java.util.Scanner;

public class Payroll3 {

    // main begin Java application
    public static void main (String[] args) {
        Employee emp = new Employee();
        Scanner input = new Scanner(System.in);

        double payRate;
        double hoursWorked;
        double earnedPay;

        while (true)
        {
            System.out.println("\nEnter Employee Name :");
            emp.setName(input.next());

            if (!emp.getName().equals("Stop")) {
                System.out.print ("Enter Employee payRate: $"); //prompt
                emp.setpayRate(input.nextDouble());
                while (emp.getpayRate() <= 0) {
                    System.out.println ("Invalid amount, setpayRate must be positive");
                    System.out.print ("Please enter valid payrate: $");
                    emp.setpayRate(input.nextDouble());
                    // Loop until valid number is entered for payrate: while (setpayRate < 0.0)
                } // end while
                System.out.print ("Enter number hours worked: ");
                emp.sethoursWorked(input.nextDouble());
                while (emp.gethoursWorked() <= 0 ) {
                    System.out.println ("Invalid amount, hoursWorked must be positive");
                    System.out.print ("Please enter valid hourWorked: ");
                    emp.sethoursWorked(input.nextDouble());
                }
                System.out.printf("%s's weekly earned pay is: $%.2f\n", emp.getName(), emp.getpayRate());
            } else
                break;
        } // end while (true)

    } // end main

}//end class Payroll3


//  Class Employee
class Employee
{
    private String name;
    private double hourlyRate;
    private double hoursWorked;

    public Employee ()
    {
        //implicit call to object constructor occurs here
        name = "";
        hourlyRate = 0.0;
        hoursWorked = 0.0;
    }

    // Three argument initialization constructor
    public Employee(String employeenameIn, double hourlyRateInDollarsIn, double hoursWorkedInWeekIn) {
        //implicit call to object constructor occurs here