Results 1 to 10 of 10
Thread: crating an object error..
- 02-28-2011, 10:12 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 28
- Rep Power
- 0
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)
- 02-28-2011, 10:18 PM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
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.
- 02-28-2011, 10:18 PM #3
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Can't do much without seeing the Payroll class code. Do you have constructors set up correctly?
- 02-28-2011, 10:19 PM #4
Senior Member
- Join Date
- Feb 2011
- Posts
- 118
- Rep Power
- 0
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.
- 02-28-2011, 11:04 PM #5
Member
- Join Date
- Feb 2011
- Posts
- 28
- Rep Power
- 0
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..
thanks you guys!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; } }Last edited by glina126; 02-28-2011 at 11:06 PM.
Still a newbee.. on chapter 7 of 15 in the book "Starting out with Java", by Tony Gaddis. :) (GUIs!!!! :D)
- 02-28-2011, 11:12 PM #6
No you didn't.Java Code:public Payroll(String str, int number)
- 02-28-2011, 11:12 PM #7
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Looks like you created a constructor which takes a String and an int, then passed it a String and a double.
- 02-28-2011, 11:13 PM #8
Member
- Join Date
- Feb 2011
- Posts
- 28
- Rep Power
- 0
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)
- 02-28-2011, 11:16 PM #9
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Glad you solved it, please mark your thread solved with the thread tools at the top.
- 03-01-2011, 12:36 AM #10
Member
- Join Date
- Feb 2011
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
Socket/ObjectOutputStream/Very Simple Object serialization error
By L337CodeMonkey in forum NetworkingReplies: 3Last Post: 02-08-2011, 07:45 PM -
error at object to int
By arieana in forum New To JavaReplies: 5Last Post: 12-07-2010, 02:48 AM -
object new and pointers error
By hydride in forum New To JavaReplies: 2Last Post: 04-06-2010, 06:15 PM -
Error showing "Object Required"
By kishan in forum Advanced JavaReplies: 2Last Post: 09-26-2009, 02:23 PM -
Error loading object from file : C:\Date.jrxml Jass Report
By cecily in forum JDBCReplies: 2Last Post: 12-03-2008, 11:14 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks