Question

Payroll Class

Asked by: AgentC4

Hi, I'm trying to figure out my homework assignment but i get errors.

THIS IS THE ASSIGNMENT:

Design a payroll class that has fields for an employee's name, ID number, hourly pay rate, and number of hours worked. Write approperiate accessor and mutator methods and a constructor that accepts the employee's name and ID as arguments. the class should also have a method that returns the employees gross pay rate. Write a program that demonstrates the class by creating a Payroll object, then asking the user to enter the data for an employee. The program should display the amount of gross pay earned.

MY CODE IS BELOW ALONG WITH ERROR MESSAGES

import java.util.*;
import javax.swing.*;
import java.text.*;
import java.util.Scanner;
 
 
public class Payroll1
{
	private String EmployeeName;
	private double EmployeeID;
	private double HourlyRate;
	private double HoursWorked;
	private double GrossPay;
	
	public Payroll1(String EmployeeName)
	{
		this.EmployeeName = EmployeeName;
	}
	
	public void setEmployeeID( double EmployeeID )
	{
		this.EmployeeID = EmployeeID;
	}
	
	public double getEmployeeID()
	{
		return EmployeeID;
	}
	
	public void setHourlyRate( double HourlyRate )
	{
		this.HourlyRate = HourlyRate;
	}
	
	public double getHourlyRate()
	{
		return HourlyRate;
	}
	
	public void setHoursWorked( double HoursWorked )
	{
		this.HoursWorked = HoursWorked;
	}
	
	public double getHoursWorked()
	{
		return HoursWorked;
	}
	
	public void setGrossPay( double GrossPay )
	{
		this.GrossPay = GrossPay;
	}
	
	public double getGrossPay()
	{
		return HourlyRate * HoursWorked;
	}
	
	public static void main(String[] args)
	{
		Scanner	userInput;
		
		DecimalFormat	circle	=	new	DecimalFormat("##0.00");
		
		userInput = new Scanner (System.in);
		System.out.println("Please enter name of Employee: ");
		EmployeeName = userInput.nextLine();
		
		System.out.println("Please enter Employee ID: ");
		EmployeeID = Double.nextDouble();
		
		System.out.println("Please enter Hourly Rate: ");
		HourlyRate = Double.nextDouble();
		
		System.out.println("Please enter Hours Worked: ");
		HoursWorked = Double.nextDouble();
		
		System.out.println("The employee name's is: " + EmployeeName);
		System.out.println("The employee ID is: " + EmployeeID);
		System.out.println("The employee's gross pay is: " + GrossPay);
	}
	
	
	
}

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-05 at 20:31:36ID24630237
Topics

NetBeans IDE

,

jEdit Editor

,

Java Programming Language

Participating Experts
3
Points
500
Comments
49

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Constructor
    I am planning to develop a class program with the following attributes  The name of the item a String  The quantity in stock an integer  The current price of the item ( a double) The methods of class item should include  Constru...
  2. Calculation payroll
    This program is supposed to calculate payroll. Been struggnling around for hours There is a problem with the calculation fonction. It returns 0 like the calculation isn't working. Any help would be appreciated. Here are the requirements: The program requirements are: · ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: AgentC4Posted on 2009-08-05 at 20:32:15ID: 25029937

these are my errors


Payroll1.java:74: non-static variable EmployeeName cannot be referenced from a static context
            EmployeeName = userInput.nextLine();
                ^
Payroll1.java:77: non-static variable EmployeeID cannot be referenced from a static context
            EmployeeID = Double.nextDouble();
                ^
Payroll1.java:77: cannot find symbol
symbol  : method nextDouble()
location: class java.lang.Double
            EmployeeID = Double.nextDouble();
                                   ^
Payroll1.java:80: non-static variable HourlyRate cannot be referenced from a static context
            HourlyRate = Double.nextDouble();
                ^
Payroll1.java:80: cannot find symbol
symbol  : method nextDouble()
location: class java.lang.Double
            HourlyRate = Double.nextDouble();
                                   ^
Payroll1.java:83: non-static variable HoursWorked cannot be referenced from a static context
            HoursWorked = Double.nextDouble();
                ^
Payroll1.java:83: cannot find symbol
symbol  : method nextDouble()
location: class java.lang.Double
            HoursWorked = Double.nextDouble();
                                    ^
Payroll1.java:85: non-static variable EmployeeName cannot be referenced from a static context
            System.out.println("The employee name's is: " + EmployeeName);
                                                                ^
Payroll1.java:86: non-static variable EmployeeID cannot be referenced from a static context
            System.out.println("The employee ID is: " + EmployeeID);
                                                            ^
Payroll1.java:87: non-static variable GrossPay cannot be referenced from a static context
            System.out.println("The employee's gross pay is: " + GrossPay);

 

by: objectsPosted on 2009-08-05 at 20:53:02ID: 25030009

One of my most often asked questions :)  You will find the problem explained here:

http://helpdesk.objects.com.au/java/im-getting-the-error-cannot-make-a-static-reference-to-the-non-static-field-when-compiling-my-class-how-do-i-fix-it

So what you need to do create an instance of Payroll1 and call its setters to sassign the various vaules

                System.out.println("Please enter name of Employee: ");
                Payroll1 payroll = new Payroll1(userInput.nextLine());
               
                System.out.println("Please enter Employee ID: ");
                payroll.setEmployeeID(userInput.nextDouble());

I'll leave the rest for you to sort out, let me know if you get stuck

 

by: AgentC4Posted on 2009-08-05 at 21:00:56ID: 25030029

im a bit confused about the instance part

 

by: objectsPosted on 2009-08-05 at 21:02:38ID: 25030040

>                 Payroll1 payroll = new Payroll1(userInput.nextLine());

here is where an instance of Payroll1 gets created. This cal the constructor in your Payroll1 class

 

by: AgentC4Posted on 2009-08-05 at 21:04:43ID: 25030048

this is what i have now for the static and the errors for that issue went away

        private static String EmployeeName;
	private static double EmployeeID;
	private static double HourlyRate;
	private static double HoursWorked;
	private static double GrossPay;

                                              
1:
2:
3:
4:
5:

Select allOpen in new window

 

by: AgentC4Posted on 2009-08-05 at 21:05:08ID: 25030053

Payroll1.java:74: payroll is already defined in main(java.lang.String[])
            Payroll1 payroll = new Payroll1(userInput.nextLine());
                         ^
Payroll1.java:77: cannot find symbol
symbol  : method setEmployeeID(double)
location: class java.text.DecimalFormat
            payroll.setEmployeeID(userInput.nextDouble());
                       ^
Payroll1.java:80: cannot find symbol
symbol  : method setHourlyRate(double)
location: class java.text.DecimalFormat
            payroll.setHourlyRate(userInput.nextDouble());
                       ^
Payroll1.java:83: cannot find symbol
symbol  : method setHoursWorked(double)
location: class java.text.DecimalFormat
            payroll.setHoursWorked(userInput.nextDouble());

 

by: AgentC4Posted on 2009-08-05 at 21:59:35ID: 25030227

i've made changes. im using the JOption pane now so it looks like the code below. but everytime i enter info this is what i get.


The employees's name is: null  ( i entered John )
The employees's ID is: 0.0        ( i entered 45 )
The employees's hourly rate is: 0.00  ( i entered 5.00 )
The hours worked are: 0.00      ( i entered 50 )
The employee's gross pay is: 0.00  ( calculation of Hourly Pay * Hours Worked )

import java.util.*;
import javax.swing.*;
import java.text.*;
import java.util.Scanner;
 
 
public class Payroll
{
	private static String EmployeeName;
	private static double EmployeeID;
	private static double HourlyRate;
	private static double HoursWorked;
	private static double GrossPay;
	
	public Payroll(String EmployeeName)
	{
		this.EmployeeName = EmployeeName;
	}
	
	public void setEmployeeID( double EmployeeID )
	{
		this.EmployeeID = EmployeeID;
	}
	
	public double getEmployeeID()
	{
		return EmployeeID;
	}
	
	public void setHourlyRate( double HourlyRate )
	{
		this.HourlyRate = HourlyRate;
	}
	
	public double getHourlyRate()
	{
		return HourlyRate;
	}
	
	public void setHoursWorked( double HoursWorked )
	{
		this.HoursWorked = HoursWorked;
	}
	
	public double getHoursWorked()
	{
		return HoursWorked;
	}
	
	public void setGrossPay( double GrossPay )
	{
		this.GrossPay = GrossPay;
	}
	
	public double getGrossPay()
	{
		return HourlyRate * HoursWorked;
	}
	
	public static void main(String[] args)
	{
		String input;
		
		DecimalFormat	payroll	=	new	DecimalFormat("##0.00");
		
		
		input = JOptionPane.showInputDialog("Please enter the employees's name: ");
		System.out.println("The employees's name is: " + EmployeeName);
													
		
		input = JOptionPane.showInputDialog("Please enter Employee ID: ");
		System.out.println("The employees's ID is: " + EmployeeID);
		
		input = JOptionPane.showInputDialog("Please enter hourly rate: ");
		System.out.println("The employees's hourly rate is: " + payroll.format(HourlyRate));
		
		input = JOptionPane.showInputDialog("Please enter hours worked: ");
		System.out.println("The hours worked are: " + payroll.format(HoursWorked));
		
		System.out.println("The employee's gross pay is: " + payroll.format(GrossPay));
 
	}
 
	
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:

Select allOpen in new window

 

by: ksivananthPosted on 2009-08-05 at 23:01:55ID: 25030451

you should store the input value to your instance and then print it, try below,

import java.util.*;
import javax.swing.*;
import java.text.*;
import java.util.Scanner;
 
 
public class Payroll
{
      private String EmployeeName;
      private double EmployeeID;
      private double HourlyRate;
      private double HoursWorked;
      private double GrossPay;
      
      public Payroll(String EmployeeName)
      {
            this.EmployeeName = EmployeeName;
      }
      
      public void setEmployeeID( double EmployeeID )
      {
            this.EmployeeID = EmployeeID;
      }
      
      public double getEmployeeID()
      {
            return EmployeeID;
      }
      
      public void setHourlyRate( double HourlyRate )
      {
            this.HourlyRate = HourlyRate;
      }
      
      public double getHourlyRate()
      {
            return HourlyRate;
      }
      
      public void setHoursWorked( double HoursWorked )
      {
            this.HoursWorked = HoursWorked;
      }
      
      public double getHoursWorked()
      {
            return HoursWorked;
      }
      
      public void setGrossPay( double GrossPay )
      {
            this.GrossPay = GrossPay;
      }
      
      public double getGrossPay()
      {
            return HourlyRate * HoursWorked;
      }
      
      public static void main(String[] args)
      {
            String input;
            
            Payroll payroll      =      new      Payroll() ;
            DecimalFormat      df      =      new      DecimalFormat("##0.00");
            
            input = JOptionPane.showInputDialog("Please enter the employees's name: ");
payroll.setEmployeeName( input ) ;
            System.out.println("The employees's name is: " + payroll.getEmployeeName() );
                                                                              
            
            input = JOptionPane.showInputDialog("Please enter Employee ID: ");
payroll.setEmployeeID( input ) ;
            System.out.println("The employees's ID is: " + payroll.getEmployeeID() );
            
            input = JOptionPane.showInputDialog("Please enter hourly rate: ");
payroll.setHourlyRate( df.format(input ) ) ;
            System.out.println("The employees's hourly rate is: " + payroll.getHourlyRate());
            
            input = JOptionPane.showInputDialog("Please enter hours worked: ");
payroll.setHoursWorked( df.format(input ) ) ;
            System.out.println("The hours worked are: " + payroll.getHoursWorked());
            
            input = JOptionPane.showInputDialog("Please enter GrossPay: ");
payroll.setGrossPay( df.format(input ) ) ;
            System.out.println("The employee's gross pay is: " + payroll.getGrossPay());
 
      }
 
      
}

 

by: AgentC4Posted on 2009-08-06 at 07:16:54ID: 25033601

i keep getting errors left and right


Payroll.java:72: cannot find symbol
symbol  : constructor Payroll()
location: class Payroll
            Payroll payroll      =      new      Payroll() ;
                                            ^
Payroll.java:75: cannot find symbol
symbol  : method setEmployeeName(java.lang.String)
location: class Payroll
            payroll.setEmployeeName( input ) ;
                       ^
Payroll.java:76: cannot find symbol
symbol  : method getEmployeeName()
location: class Payroll
            System.out.println("The employees's name is: " + payroll.getEmployeeName());
                                                                        ^
Payroll.java:80: setEmployeeID(double) in Payroll cannot be applied to (java.lang.String)
            payroll.setEmployeeID( input );
                       ^
Payroll.java:84: setHourlyRate(double) in Payroll cannot be applied to (java.lang.String)
            payroll.setHourlyRate( df.format(input ) ) ;
                       ^
Payroll.java:88: setHoursWorked(double) in Payroll cannot be applied to (java.lang.String)
            payroll.setHoursWorked( df.format(input ) ) ;
                       ^
Payroll.java:91: cannot find symbol
symbol  : method format(double)
location: class Payroll
            System.out.println("The employee's gross pay is: " + payroll.format(GrossPay));

 

by: AgentC4Posted on 2009-08-06 at 07:25:02ID: 25033704

im working with just this code right now to try to figure out why its givng me errors


Payroll.java:70: cannot find symbol
symbol  : constructor Payroll()
location: class Payroll
            Payroll payroll = new Payroll();
                                  ^
Payroll.java:74: cannot find symbol
symbol  : method setEmployeeName(java.lang.String)
location: class Payroll
            payroll.setEmployeeName( input ) ;
                       ^
Payroll.java:75: cannot find symbol
symbol  : method getEmployeeName()
location: class Payroll
            System.out.println("The employee's name is: " + payroll.getEmployeeName());

public static void main(String[] args)
	{
		String input;
		
		Payroll payroll = new Payroll();
		DecimalFormat	df	=	new	DecimalFormat("##0.00");
				
		input = JOptionPane.showInputDialog("Please enter the employee's name: ");
		payroll.setEmployeeName( input ) ;
		System.out.println("The employee's name is: " + payroll.getEmployeeName());

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:

Select allOpen in new window

 

by: objectsPosted on 2009-08-06 at 16:14:20ID: 25038925

you don't appear to be following what I suggested. Can't help you if thats the case

 

by: AgentC4Posted on 2009-08-06 at 16:27:35ID: 25038972

i changed it to static and working with it

 

by: objectsPosted on 2009-08-06 at 16:34:23ID: 25038991

you shouldn't change it to static, you can only store a single employees details if you do that.

 

by: AgentC4Posted on 2009-08-06 at 16:40:16ID: 25039016

i figured it would be that case thats why im trying both static and non static and see if it displays only whats stored and or whats entered. right now im doing non static becuase i want it to use the info i enter but all i get is 0's and errors :

Payroll.java:70: cannot find symbol
symbol  : constructor Payroll()
location: class Payroll
            Payroll payroll = new Payroll();
                                  ^
Payroll.java:74: cannot find symbol
symbol  : method setEmployeeName(java.lang.String)
location: class Payroll
            payroll.setEmployeeName( input ) ;
                       ^
Payroll.java:75: cannot find symbol
symbol  : method getEmployeeName()
location: class Payroll
            System.out.println("The employee's name is: " + payroll.getEmployeeName());

 

by: objectsPosted on 2009-08-06 at 16:44:07ID: 25039032

well good luck with it :)  If you get stuck go back to my first comment and try what I suggested, it should fix all your problems.

 

by: AgentC4Posted on 2009-08-06 at 19:07:29ID: 25039556

i created a PayrollTest class. i kept the other class by itself with no main method. codes are below, i keep getting errors and i dont know what the heck is going on.


Payroll Class

import java.util.*;
import javax.swing.*;
import java.text.*;
 
 
public class Payroll
{
	private String EmployeeName;
	private double EmployeeID;
	private double HourlyRate;
	private double HoursWorked;
	private double GrossPay;
	
	public Payroll(String EmployeeName)
	{
		this.EmployeeName = EmployeeName;
	}
	
	public Payroll()
	{
	
	}
	
	public void setEmployeeName()
	{
		
	}
	
	public void setEmployeeID( double EmployeeID )
	{
		this.EmployeeID = EmployeeID;
	}
	
	public double getEmployeeID()
	{
		return EmployeeID;
	}
	
	public void setHourlyRate( double HourlyRate )
	{
		this.HourlyRate = HourlyRate;
	}
	
	public double getHourlyRate()
	{
		return HourlyRate;
	}
	
	public void setHoursWorked( double HoursWorked )
	{
		this.HoursWorked = HoursWorked;
	}
	
	public double getHoursWorked()
	{
		return HoursWorked;
	}
	
	public void setGrossPay( double GrossPay )
	{
		this.GrossPay = GrossPay;
	}
	
	public double getGrossPay()
	{
		return HourlyRate * HoursWorked;
	}
	
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:

Select allOpen in new window

 

by: AgentC4Posted on 2009-08-06 at 19:08:59ID: 25039566

Payroll Test Class with just first part which is employee name

   import java.util.*;
   import javax.swing.*;
   import java.text.*;
 
 
    public class PayrollTest
   {
       public static void main(String[] args)
      {
         String input;
         String EmployeeName;
         double EmployeeID;
         double HourlyRate;
         double HoursWorked;
         double GrossPay;
      
         Payroll payroll = new Payroll();
      
         input = JOptionPane.showInputDialog("Please enter the employee's name: ");
         payroll.setEmployeeName(input) ;
         System.out.println("The employee's name is: " + Payroll.getEmployeeName());

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:

Select allOpen in new window

 

by: mwvisa1Posted on 2009-08-09 at 07:38:03ID: 25054338

I strongly feel objects answered the question in the very first post and then your next issue was simply you were missing some variable/method declarations which is the meaning of "symbol not found" error.

Anyway, I will take a look at your recent code and see where you have errors.

 

by: mwvisa1Posted on 2009-08-09 at 07:45:21ID: 25054365

Notes on your PayrollTest class:

import javax.swing.JOptionPane;
 
 
public class PayrollTest {
 
    public static void main(String[] args) {
        String input;
 
        /* These should not be necessary -- Payroll stores
        String EmployeeName;
        double EmployeeID;
        double HourlyRate;
        double HoursWorked;
        double GrossPay;
        */
 
        Payroll payroll = new Payroll();
 
        input = JOptionPane
                .showInputDialog("Please enter the employee's name: ");
        // you didn't add parameter to setEmployeeName
        // see notes in Payroll class
        payroll.setEmployeeName(input); 
        
        // you don't have a getEmployeeName defined in Payroll class
        System.out.println("The employee's name is: "
                + Payroll.getEmployeeName());
    } // added to make class complete
} // added to make class complete

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:

Select allOpen in new window

 

by: mwvisa1Posted on 2009-08-09 at 07:52:49ID: 25054384

Notes on Payroll class.

public class Payroll {
 
    /* try to follow standard practices */
    // java naming convention employeeName
    private String EmployeeName;
 
    private double EmployeeID;
    private double HourlyRate;
    private double HoursWorked;
 
    // unnecessary, since GrossPay is computed
    private double GrossPay;
 
    public Payroll(String EmployeeName) {
        this.EmployeeName = EmployeeName;
    }
 
    public Payroll() {
 
    }
 
    // not actually setting anything
    // should have this kind of signature for a mutator
    // public void setEmployeeName(String employeeName) { }
    public void setEmployeeName() {
 
    }
 
    // missing the accessor for employeeName
    // typical signature would be:
    // public String getEmployeeName() { }
 
    public void setEmployeeID(double EmployeeID) {
        this.EmployeeID = EmployeeID;
    }
 
    public double getEmployeeID() {
        return EmployeeID;
    }
 
    public void setHourlyRate(double HourlyRate) {
        this.HourlyRate = HourlyRate;
    }
 
    public double getHourlyRate() {
        return HourlyRate;
    }
 
    public void setHoursWorked(double HoursWorked) {
        this.HoursWorked = HoursWorked;
    }
 
    public double getHoursWorked() {
        return HoursWorked;
    }
 
    // GrossPay shouldn't be set since it is calculated
    public void setGrossPay(double GrossPay) {
        this.GrossPay = GrossPay;
    }
 
    // computes gross pay from hours and rate,
    // so no need to store a gross pay or set it.
    public double getGrossPay() {
        return HourlyRate * HoursWorked;
    }
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:

Select allOpen in new window

 

by: AgentC4Posted on 2009-08-09 at 09:49:40ID: 25054784

PayrollTest.java:29: non-static method getEmployeeName() cannot be referenced from a static context
                + Payroll.getEmployeeName());

nothing in the code is static so i dont understand why its talking about static. and when i change it to static it compiles and run fine but when it displays the output which should be "john" (example ), all i get is NULL for an output

 

by: mwvisa1Posted on 2009-08-09 at 09:53:57ID: 25054807

Sorry missed a comment.

Payroll.getEmployeeName()

Should be:

payroll.getEmployeeName()

Remember Java is case sensitive.  Your variable is payroll.  When you type Payroll, it doesn't see that as the same as payroll.  Coincidentally, in your case, the class name is Payroll.  Therefore, you get error as it thinks you are trying to access a static method of the Payroll class called getEmployeeName as that is a static style call.  You don't want to change it to static, you want to change the call as I showed.

 

by: mwvisa1Posted on 2009-08-09 at 09:54:38ID: 25054810

For more information on Java syntax, you should have a look here:
http://java.sun.com/docs/books/tutorial/

 

by: AgentC4Posted on 2009-08-09 at 09:59:30ID: 25054829

well im not getting the error anymore but i tried it with and without the uppercase and it compiled both times with no errors. my only issue is that it displays NULL like this:

The employee's name is: NULL ( when entereing any name, john, mark, steve etc )

 

by: mwvisa1Posted on 2009-08-09 at 10:03:18ID: 25054849

Can you post the corrected Payroll class.

 

by: AgentC4Posted on 2009-08-09 at 10:05:38ID: 25054859

this is the Class

public class Payroll 
{
    private String EmployeeName;
    private double EmployeeID;
    private double HourlyRate;
    private double HoursWorked;
 
   
    private double GrossPay;
 
    public Payroll(String EmployeeName) 
	 {
      this.EmployeeName = EmployeeName;
    }
 
    public Payroll() 
	 {
 
    }
 
    public void setEmployeeName(String employeeName) { }
	  
    public String getEmployeeName() 
	 {
	  	return EmployeeName; 
	 }
 
    public void setEmployeeID(double EmployeeID) 
	 {
      this.EmployeeID = EmployeeID;
    }
 
    public double getEmployeeID() 
	 {
      return EmployeeID;
    }
 
    public void setHourlyRate(double HourlyRate) 
	 {
      this.HourlyRate = HourlyRate;
    }
 
    public double getHourlyRate() 
	 {
      return HourlyRate;
    }
 
    public void setHoursWorked(double HoursWorked) 
	 {
      this.HoursWorked = HoursWorked;
    }
 
    public double getHoursWorked() 
	 {
      return HoursWorked;
    }
 
    public void setGrossPay(double GrossPay) 
	 {
        this.GrossPay = GrossPay;
    }
 
    public double getGrossPay() 
	 {
        return HourlyRate * HoursWorked;
    }
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:

Select allOpen in new window

 

by: AgentC4Posted on 2009-08-09 at 10:06:41ID: 25054861

and this is the Test class
Both compile with no errors, but no names come up

import javax.swing.JOptionPane;
 
 
public class PayrollTest 
{
 
    public static void main(String[] args) 
	 {
        String input;
 
        /* 
        String EmployeeName;
        double EmployeeID;
        double HourlyRate;
        double HoursWorked;
        double GrossPay;
        */
		  
        Payroll payroll = new Payroll();
 
        input = JOptionPane.showInputDialog("Please enter the employee's name: ");
        payroll.setEmployeeName(input); 
        
       
        System.out.println("The employee's name is: "
                + payroll.getEmployeeName());
    } 
} 

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:

Select allOpen in new window

 

by: mwvisa1Posted on 2009-08-09 at 10:09:24ID: 25054870

Look at line 21: public void setEmployeeName(String employeeName) { }
        
You are still not setting the variable.  Try like this:

public class Payroll {
 
    private String employeeName;
 
    private double employeeID;
    private double hourlyRate;
    private double hoursWorked;
 
    public Payroll(String employeeName) {
        this.employeeName = employeeName;
    }
 
    public Payroll() {
 
    }
 
    // see change here
    public void setEmployeeName(String employeeName) {
        this.employeeName = employeeName;
    }
 
    public String getEmployeeName() {
        return employeeName;
    }
 
    public void setEmployeeID(double employeeID) {
        this.employeeID = employeeID;
    }
 
    public double getEmployeeID() {
        return employeeID;
    }
 
    public void setHourlyRate(double hourlyRate) {
        this.hourlyRate = hourlyRate;
    }
 
    public double getHourlyRate() {
        return hourlyRate;
    }
 
    public void setHoursWorked(double hoursWorked) {
        this.hoursWorked = hoursWorked;
    }
 
    public double getHoursWorked() {
        return hoursWorked;
    }
 
    public double getGrossPay() {
        return hourlyRate * hoursWorked;
    }
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:

Select allOpen in new window

 

by: AgentC4Posted on 2009-08-09 at 10:23:50ID: 25054967

i noticed some of your (employee) are lowercase and uppercase for the (E), except for the getEmployeeName where the E is uppercased. I'm guessing thats whats causing the NULL for an answer

 

by: mwvisa1Posted on 2009-08-09 at 10:47:02ID: 25055091

No!

I had changed that code to show you the Java naming conventions.  The change I was pointing to is the actually setting of variable:

this.employeeName = employeeName;

Hope that makes sense.

 

by: AgentC4Posted on 2009-08-09 at 10:50:20ID: 25055105

ok thats what i thought i didnt think it would be that. Yea it makes sense. still gives me null

 

by: mwvisa1Posted on 2009-08-09 at 11:05:58ID: 25055178

When I tried I got valid results, so not sure why it didn't work for you.  To be safe, try it with my version of Payroll class.

 

by: AgentC4Posted on 2009-08-09 at 11:25:29ID: 25055292

i tried both yours and my Payroll Class and all i get when i compile, run, and enter any name in the Payroll Test , i get this:

The employee's name is: null

 

by: mwvisa1Posted on 2009-08-09 at 11:35:34ID: 25055346

Here is what I am using.  To me the files look the same; however, you can try with mine.

To make sure it is not picking up the old version of PayrollTest, I would run a compile and clean on project (try closing and re-opening Netbeans) in case it is cached version.  Then right-click on the PayrollTest file and run from there to ensure it is running this new version and not another in your project that happens to have a main method.

import javax.swing.JOptionPane;
 
 
public class PayrollTest {
 
    public static void main(String[] args) {
        String input;
 
        Payroll payroll = new Payroll();
 
        input = JOptionPane
                .showInputDialog("Please enter the employee's name: ");
        payroll.setEmployeeName(input); 
        
        System.out.println("The employee's name is: "
                + payroll.getEmployeeName());
    } 
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:

Select allOpen in new window

 

by: AgentC4Posted on 2009-08-09 at 11:39:24ID: 25055367

Im using jGRASP, does that matter?

 

by: mwvisa1Posted on 2009-08-09 at 11:47:34ID: 25055401

Don't know the particulars in jGRASP, but should have something similar where you can compile your project and/or clean project.  For the latter, as stated earlier, you can just close out and re-open then try to ensure that the run command is definitely executing main from our updated PayrollTest class versus a different compilation/implementation.

 

by: AgentC4Posted on 2009-08-09 at 11:48:04ID: 25055403

ok, this time it worked. Now i just have to do the same for the ID, Hours worked, Hourly rate, and Gross pay. But for those im gussing i would need to use the (Ingeter) and or (Double.parse) for those becuase im dealing with numbers

 

by: mwvisa1Posted on 2009-08-09 at 11:49:20ID: 25055408

You are correct.

 

by: AgentC4Posted on 2009-08-09 at 11:49:32ID: 25055409

and im asking that becuase this is what i get

PayrollTest.java:18: setEmployeeID(double) in Payroll cannot be applied to (java.lang.String)
        payroll.setEmployeeID(input);

 

by: AgentC4Posted on 2009-08-09 at 12:09:58ID: 25055466

I tried these and none work

input = JOptionPane.showInputDialog("Please enter the employee's ID: ");
        payroll = Double.nextDouble(input); 	
		  
		  System.out.println("The employee's name is: "
                           + payroll.getEmployeeID());
// OR //
 
input = JOptionPane.showInputDialog("Please enter the employee's ID: ");
        EmployeeID = Double.nextDouble(input); 	
		  
		  System.out.println("The employee's name is: "
                           + getEmployeeID());
 
// OR //
 
input = JOptionPane.showInputDialog("Please enter the employee's ID: ");
        EmployeeID = Integer.parseInt(input); 	
		  
		  System.out.println("The employee's name is: "
                           + getEmployeeID());
 
// OR //
 
input = JOptionPane.showInputDialog("Please enter the employee's ID: ");
        payroll.setEmployeeID(input); 	
		  
		  System.out.println("The employee's name is: "
                           + payroll.getEmployeeID());
 
// OR //
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:

Select allOpen in new window

 

by: mwvisa1Posted on 2009-08-09 at 12:15:26ID: 25055490

Since you declared employeeID as a double data type, this would be correct.

payroll.setEmployeeID(Double.parse(input));

                                              
1:

Select allOpen in new window

 

by: AgentC4Posted on 2009-08-09 at 12:30:07ID: 25055562

PayrollTest.java:28: cannot find symbol
symbol  : method parse(java.lang.String)
location: class java.lang.Double
        payroll.setEmployeeID(Double.parse(input));
                                                       ^

i dont think it would be the import files cuz i have all of them set.

 

by: mwvisa1Posted on 2009-08-09 at 12:32:06ID: 25055575

I apologize, I typed that in the text box without verifying. :) parseDouble not parse.

payroll.setEmployeeID(Double.parseDouble(input));

                                              
1:

Select allOpen in new window

 

by: AgentC4Posted on 2009-08-09 at 12:45:38ID: 25055641

finished Test class

so obviously i got work to do on learning more on how this works.

public class PayrollTest 
{
 
    public static void main(String[] args) 
	 {
        String input;
 
        Payroll payroll = new Payroll();
 
        input = JOptionPane.showInputDialog("Please enter the employee's name: ");
        payroll.setEmployeeName(input);         
        System.out.println("The employee's name is: " + payroll.getEmployeeName());
					 
		  input = JOptionPane.showInputDialog("Please enter the employee's ID: ");
        payroll.setEmployeeID(Double.parseDouble(input));		  
		  System.out.println("The employee's ID is: " + payroll.getEmployeeID());
		  
		  input = JOptionPane.showInputDialog("Please enter the hours worked: ");
        payroll.setHoursWorked(Double.parseDouble(input));		  
		  System.out.println("The hours worked are: " + payroll.getHoursWorked());
		  
		  input = JOptionPane.showInputDialog("Please enter the hourly wage: ");
        payroll.setHourlyRate(Double.parseDouble(input));
		  System.out.println("The employee's hourly wage is: " + payroll.getHourlyRate());
		  
		  System.out.println("The employee's gross pay is: " + payroll.getGrossPay());
    } 
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:

Select allOpen in new window

 

by: mwvisa1Posted on 2009-08-09 at 12:51:15ID: 25055660

Yes, definitely want to understand the code -- see my comment here -- http:#25054810 -- for a good link to start with.

 

by: AgentC4Posted on 2009-08-09 at 13:30:01ID: 25055801

thanks, ill get started on it.

 

by: mwvisa1Posted on 2009-08-09 at 13:40:17ID: 25055850

Good luck.

Happy coding!

Regards,
isa

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...