Results 1 to 10 of 10
  1. #1
    glina126 is offline Member
    Join Date
    Feb 2011
    Posts
    28
    Rep Power
    0

    Default crating an object error..

    hey guys, if anyone could look at the code and the error im getting and point me in the right direction i would be thankful!

    Java Code:
    
    import java.util.*;
    
    public class Payrollexec
    {
    	public static void main(String[] args)
    	{
    		String name = "John Smith";
    		double number = 0;
    		
    		
    		Scanner keyboard = new Scanner(System.in);
    		
    		System.out.print("What is your name? ");
    		name = keyboard.nextLine();
    		
    		System.out.print("What is your ID number? ");
    		number = keyboard.nextInt();
    		
    		// create an object and send values to a consructor.
    		Payroll referee = new Payroll(name, number);
    		
    		System.out.print("What is your hourly rate? ");
    		number = keyboard.nextInt();
    		
    		// setHrsWorked
    		referee.setHrRate(number);
    		
    		
    		System.out.print("How many hours have you worked? ");
    		number = keyboard.nextInt();
    		
    		// call class setHrsWorked
    		referee.setHrsWorked(number);
    		
    		System.out.println("Your name is " + referee.getName() + " and your emloyee ID number is " + referee.getId() + 
    							"\n and your gross pay is " + referee.gross());
    		
    	}
    }

    and this is the error im getting.




    also, i did compile the Payroll class that im referring to. I dont know why it wont create a new object :?
    Still a newbee.. on chapter 7 of 15 in the book "Starting out with Java", by Tony Gaddis. :) (GUIs!!!! :D)

  2. #2
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    Is the Payroll file in the same directory? Does it have a (String, double) constructor? Post the code, we'll see what's going on.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Can't do much without seeing the Payroll class code. Do you have constructors set up correctly?

  4. #4
    NRitH is offline Senior Member
    Join Date
    Feb 2011
    Posts
    118
    Rep Power
    0

    Default

    The Payroll class must not be on your compiler's classpath.

    Wait, scratch that. The Payroll class doesn't have a constructor that takes a string and a double. Check what parameter types its constructor does take.

  5. #5
    glina126 is offline Member
    Join Date
    Feb 2011
    Posts
    28
    Rep Power
    0

    Default

    hmm i dont know whats going on. i did create a constructor that takes a string and a double. here is the Payroll code
    also, they are in the same path..

    Java Code:
    
    /*************************************************************************
    ** PAYROLL																**
    **	This program calculates how much one should get paid using classes*	**
    *************************************************************************/
    
    
    import java.util.*;
    
    public class Payroll
    {
    	private String name;
    	private int idNumber;
    	private double hourlyRate;
    	private double hoursWorked;
    	
    	
    	// This constructor sets the name of the client
    	// This constructor sets the clients id number
    	public Payroll(String str, int number)
    	{		
    		name = str;
    		idNumber = number;
    	}
    	
    	// this method will set the hourly rate. 
    	public void setHrRate(double number)
    	{
    		hourlyRate = number;
    	}
    	
    	// this method will set the hours worked. 
    	public void setHrsWorked(double number)
    	{
    		hoursWorked = number;
    	}
    	
    	// this method will get the name
    	public String getName()
    	{
    		return name;
    	}
    	
    	// this method will get the id number.
    	public int getId()
    	{
    		return idNumber;
    	}
    	
    	// this method will get the hourly rate.
    	public double getHrRate()
    	{
    		return hourlyRate;
    	}
    	
    	// this method will get the hours worked.
    	public double hrsWorked()
    	{
    		return hoursWorked;
    	}
    	
    	// this method will get the gross pay. 
    	public double gross()
    	{
    		double gross;
    		return gross = hoursWorked * hourlyRate;
    	}
    }
    thanks you guys!
    Last edited by glina126; 03-01-2011 at 12:06 AM.
    Still a newbee.. on chapter 7 of 15 in the book "Starting out with Java", by Tony Gaddis. :) (GUIs!!!! :D)

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Java Code:
    public Payroll(String str, int number)
    No you didn't.

  7. #7
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Looks like you created a constructor which takes a String and an int, then passed it a String and a double.

  8. #8
    glina126 is offline Member
    Join Date
    Feb 2011
    Posts
    28
    Rep Power
    0

    Default

    Found the error! thanks you guys! I had the int vs double mismatch kind of deal. fixed and working! thanks a bunch!
    Still a newbee.. on chapter 7 of 15 in the book "Starting out with Java", by Tony Gaddis. :) (GUIs!!!! :D)

  9. #9
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Glad you solved it, please mark your thread solved with the thread tools at the top.

  10. #10
    glina126 is offline Member
    Join Date
    Feb 2011
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by sunde887 View Post
    Glad you solved it, please mark your thread solved with the thread tools at the top.
    thanks! didnt know i could do that! ;)
    Still a newbee.. on chapter 7 of 15 in the book "Starting out with Java", by Tony Gaddis. :) (GUIs!!!! :D)

Similar Threads

  1. Replies: 3
    Last Post: 02-08-2011, 08:45 PM
  2. error at object to int
    By arieana in forum New To Java
    Replies: 5
    Last Post: 12-07-2010, 03:48 AM
  3. object new and pointers error
    By hydride in forum New To Java
    Replies: 2
    Last Post: 04-06-2010, 07:15 PM
  4. Error showing "Object Required"
    By kishan in forum Advanced Java
    Replies: 2
    Last Post: 09-26-2009, 03:23 PM
  5. Replies: 2
    Last Post: 12-03-2008, 12:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •