Results 1 to 15 of 15
  1. #1
    gnarly hogie is offline Member
    Join Date
    Oct 2008
    Posts
    34
    Rep Power
    0

    Default Help with classes

    I'm learning how to make classes in school and everything works fine and dandy over there but when I try to make classes at home and use them at my house i get an error

    cannot find symbol constructor EmployeeGriggs(java.lang.String,int)

    I have saved both files and they are in the same folder if that even matters any help?

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default More info...

    Please post the code so we can see where the problem is. Remember to wrap the text that has code section using the "CODE Tag" (third icon above from right to left).
    CJSL

  3. #3
    gnarly hogie is offline Member
    Join Date
    Oct 2008
    Posts
    34
    Rep Power
    0

    Default

    This is the class

    Java Code:
    /**
     *Chris Griggs
     *October 9
     */
    
    
    public class EmployeeGriggs {
    
    public String Employee;//These two variables can be used by all the methods
    public Double Salary;
    
        public void EmployeeGriggs(String EmployeeName, Double CurrentSalary) {
        	
        	Employee = EmployeeName;//takes the employees name and puts into the employee variable for use by the methods
        	Salary = CurrentSalary;//takes the salary and puts in the salary  variable for use by the methods
        	
        }
        
        public String GetName(){
        	return Employee;//sends out whatever is in the variable at the time when called on 
        }
        
        public double GetSalary(){
        	return Salary;//sends out whatever is in the variable at the time when called on 
        }
        
        public void raiseSalary(double percent){
        	percent = percent/100; //divides the variabe percent by a hundred to make it into a decimal
        	double NewSalary = Salary * percent;//creates a new variable and finds how much the increase will be 
        	Salary = NewSalary * Salary;//adds the increase and current salary together
        }
    }
    This is the driver

    Java Code:
    /**
     *Chris Griggs
     *October 9
     */
    
    public class EmployeeTesterGriggs
    {
    	public static void main(String[] args)
    	{
    		EmployeeGriggs harry = new EmployeeGriggs("Harry Hacker", 50000);//intializes the EmployeeGriggs class
    		harry.raiseSalary(10);//Raises the salary by 10 percent
    		System.out.println(harry.GetName());//Calls on GetName to get a name
    		System.out.println(harry.GetSalary());//Calls on GetSalary to get a salary
    	}
    }

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default

    Where is the error message? It has the source line number and text.

    What are the types of args to the Constructor?
    what types are you passing to the constructor?
    Hint: 50000 is not a Double.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    this:
    Java Code:
    public void EmployeeGriggs(String EmployeeName, Double CurrentSalary)
    is not a constructor as it has a return type of "void". A true constructor has no return type. So try removing the void and see what happens.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Norm View Post
    Hint: 50000 is not a Double.
    I don't think that this will matter as Java will convert this number to double without much trouble. There's a name for this process, but it escapes me.

  7. #7
    gnarly hogie is offline Member
    Join Date
    Oct 2008
    Posts
    34
    Rep Power
    0

    Default

    Fubarable - I think you may mean casting

    I did take out the void and still the same error

    "cannot find symbol constructor EmployeeGriggs(java.lang.String,int)"

    it is also at line 10, could there be a problem with the IDE (JCreator) that I need to do something in the options?

  8. #8
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Not sure, but maybe

    Could it be that you're calling the class with the wrong type arguments? The second argument of your class has an int when it should be a double.
    CJSL

  9. #9
    gnarly hogie is offline Member
    Join Date
    Oct 2008
    Posts
    34
    Rep Power
    0

    Default

    Ok well I changed 50000 to 50000.0 because it has a decimal point and it compiles and runs but when I call for the salary its kinda ridiculous and comes out at 2.5E8

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default

    Try 50000.0

  11. #11
    gnarly hogie is offline Member
    Join Date
    Oct 2008
    Posts
    34
    Rep Power
    0

    Default

    OOOOO that problem may have something to do with the salary but that's a different problem. Thanks for the help guys.

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default

    It is better to use interger data types for money to prevent rounding errors. However for student exercises it doesn't matter.

    Add some println() statements to the raise method to show intermediate values so you'll know what your code is doing.\

    Salary = NewSalary * Salary;//adds ...
    Reading the coment looks like this is the problem

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by gnarly hogie View Post
    Fubarable - I think you may mean casting
    OK, it's actually called "implicit casting" and should cause no problem. The allowable implicit casts are: byte or char → short → int → long → float → double.

    Again, so using an int as a parameter value will cause no problem.

    for any non-believers:

    Java Code:
    public class ImplicitCast
    {
      public ImplicitCast(double myDouble)
      {
        System.out.println("this works as myDouble has been automatically implicitly cast: " + myDouble);
      }
      
      public static void main(String[] args)
      {
        ImplicitCast myObj = new ImplicitCast(5000);
      }
    }

  14. #14
    gnarly hogie is offline Member
    Join Date
    Oct 2008
    Posts
    34
    Rep Power
    0

    Default

    Okie dokie then now all is well thanks.

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default

    The arg was Double not double. Here's what I see:
    Java Code:
    public class TestCast {
    	public static void method(Double d) {
    		// code
    	}
    	public static void main(String[] args) {
    		TestCast.method(1);
    	}
    }/*Running: C:\Program Files\Java\jdk1.5.0_04\bin\javac.exe -cp D:\JavaDevelopment\Testing\JavaForum\;D:\JavaDevelopment -deprecation -g -Xlint TestCast.java
    
    TestCast.java:6: method(java.lang.Double) in TestCast cannot be applied to (int)
    		TestCast.method(1);
                            ^
    1 error
    Running: D:\Java\jdk1.6.0_02\bin\javac.exe -Xlint -g -deprecation -classpath D:\JavaDevelopment\;. D:\JavaDevelopment\Testing\JavaForum\TestCast.java
    
    D:\JavaDevelopment\Testing\JavaForum\TestCast.java:6: method(java.lang.Double) in TestCast cannot be applied to (int)
    		TestCast.method(1);
    		        ^
    1 error
    
    */

Similar Threads

  1. Get name of available classes
    By escuja in forum CLDC and MIDP
    Replies: 0
    Last Post: 07-26-2008, 12:03 PM
  2. Cant run my classes
    By Assaf A in forum Eclipse
    Replies: 1
    Last Post: 04-22-2008, 02:31 PM
  3. Help with classes
    By freswood in forum New To Java
    Replies: 5
    Last Post: 04-21-2008, 03:28 PM
  4. Using a JAR from other classes
    By Joe2003 in forum Advanced Java
    Replies: 1
    Last Post: 01-02-2008, 07:08 PM
  5. When do we use inner classes?
    By cruxblack in forum New To Java
    Replies: 5
    Last Post: 08-10-2007, 05:00 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
  •