Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 32

Thread: Error of "cannot find symbol"

  1. #1
    Member
    Join Date
    Apr 2009
    Posts
    31
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Error of "cannot find symbol"

    hello everyone. i am a "newb" to java and am stuck on this program for class all my code is right (as far as i can tell that is) but i seem to be getting two errors and cant figuere out why heres my code and error report.
    ERROR
    D:\PayCalculator.java:19: cannot find symbol
    symbol : class PayCheck
    location: class PayCalculator
    PayCheck aPayCheck = new PayCheck(hourlyWage, hours);
    ^
    D:\PayCalculator.java:19: cannot find symbol
    symbol : class PayCheck
    location: class PayCalculator
    PayCheck aPayCheck = new PayCheck(hourlyWage, hours);
    ^
    2 errors

    Tool completed with exit code 1
    code set 1:

    import java.util.Scanner;
     
    /**
       This program calculates the pay of an employee.
    */
    public class PayCalculator
    {
       public static void main(String[] args)
       {
     
          Scanner in = new Scanner(System.in);
     
          System.out.println("Hourly wage: ");
          double hourlyWage = in.nextDouble();
     
          System.out.println("Hours worked: ");
          double hours = in.nextDouble();
     
          PayCheck aPayCheck = new PayCheck(hourlyWage, hours);
     
          System.out.println("Pay: "+ aPayCheck.getPay());
       }
    }

    code set 2:
    public class PayCheck
    {
     
     
        public PayCheck(int PayCheck,double hours)
    {
            this.PayCheck=PayCheck;
            this.hours = hours;
     
    }
        public int getPay()
     
    {
    if(hours>40)
    PayCheck=hourlyWage*150;
     
    if(hours<=40)
    PayCheck=hourlyWage;
     
    return PayCheck;
     
    }
    private int hourlyWage;
    public int PayCheck;
    private double hours;
    }
    any and all help is greatly appriciated public class PayCheck


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: fixing these two errors

    Hello big_c and welcome to the Java Programming Forums

    You are getting the error because of this:

    PayCheck aPayCheck = new PayCheck([B]hourlyWage[/B], hours);
    hourlyWage is a double value and the PayCheck constructor is looking for an Integer value.

    You could try type casting the hourlyWage variable to Integer:

    import java.util.Scanner;
     
    /**
       This program calculates the pay of an employee.
    */
    public class PayCalculator
    {
       public static void main(String[] args)
       {
     
          Scanner in = new Scanner(System.in);
     
          System.out.println("Hourly wage: ");
          double hourlyWage = in.nextDouble();
     
          [B]int hourlyWageInt = (int)hourlyWage;[/B]
     
          System.out.println("Hours worked: ");
          double hours = in.nextDouble();
     
          PayCheck aPayCheck = new PayCheck([B]hourlyWageInt[/B], hours);
     
          System.out.println("Pay: "+ aPayCheck.getPay());
       }
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Member
    Join Date
    Apr 2009
    Posts
    31
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: fixing these two errors

    thanks for the welcoming. i just tried your suggestion and got the same errors. this program has fought me every step of the way lol

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: fixing these two errors

    Quote Originally Posted by big_c View Post
    thanks for the welcoming. i just tried your suggestion and got the same errors. this program has fought me every step of the way lol
    Even with my code you are still getting the same error?

    That is strange because it is compiling fine for me...
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: fixing these two errors

    Please make sure you change:

    PayCheck aPayCheck = new PayCheck(hourlyWage, hours);

    to
    PayCheck aPayCheck = new PayCheck(hourlyWage[B]Int[/B], hours);
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  6. #6
    Member
    Join Date
    Apr 2009
    Posts
    31
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: fixing these two errors

    i copied and pasted your code exactly and it still gives me those two errors.

  7. #7
    Member
    Join Date
    Apr 2009
    Posts
    31
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: fixing these two errors

    this is really boogieing my mind

  8. #8
    Junior Member
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: fixing these two errors

    From the errors that it is providing you, it looks like it isn't recognizing the PayCheck class. Are they in the same directory? If their not, then the program won't realize what you're trying to import with that command line.

    It wasn't the hourlyWage that was set as a double, it's the hours. So the hourlyWage is fine without the Int since you set it as an Int in the PayCheck class.

  9. #9
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: fixing these two errors

    Quote Originally Posted by EmeraldStones View Post
    From the errors that it is providing you, it looks like it isn't recognizing the PayCheck class. Are they in the same directory? If their not, then the program won't realize what you're trying to import with that command line.
    Yes you should check to make sure the PayCheck class is in the same directory as this could also be causing the problem.

    Quote Originally Posted by EmeraldStones View Post
    It wasn't the hourlyWage that was set as a double, it's the hours. So the hourlyWage is fine without the Int since you set it as an Int in the PayCheck class.
    Sorry EmeraldStones, I think you are wrong. If you look at the PayCalculator class, hourlyWage is infact set as double:

    double hourlyWage = in.nextDouble();

    And the PayCheck class constructor is looking for an Integer value and a double value in that order. The values passed to this constructor have to be Integer, Double.

    public PayCheck(int PayCheck, double hours) {

    You are trying to send:

    PayCheck aPayCheck = new PayCheck(hourlyWage, hours);
    And of course hourlyWage is a double value, not an Integer. You are sending double, double.

    This is 100% what is causing this error as you can clearly see in Eclipse:

    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  10. #10
    Member
    Join Date
    Apr 2009
    Posts
    31
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: fixing these two errors

    good morning all. heres the deal i solved those first two errors for some reason it didnt like running from my flash drive so i saved then to my computer it self but now i am getting a new error. heres the error

    C:\windows\profiles\clinton\My Documents\PayCalculator.java:21: cannot find symbol
    symbol : method getPay()
    location: class PayCheck
    System.out.println("Pay: "+ aPayCheck.getPay()) ;
    ^
    1 error

    Tool completed with exit code 1

  11. #11
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: fixing these two errors

    Are the PayCalculator & PayCheck classes both in your My Documents directory?

    This error is generated because it looks like the PayCheck class cannot be located.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  12. #12
    Member
    Join Date
    Apr 2009
    Posts
    31
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: fixing these two errors

    indeed they are. my professor said something about the method name in the class is different then the method name in the tester but i dont see how they are different.

  13. #13
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: fixing these two errors

    Quote Originally Posted by big_c View Post
    indeed they are. my professor said something about the method name in the class is different then the method name in the tester but i dont see how they are different.
    I can't see anything wrong with the code. In Eclipse it is all compiling fine.

    Could you attach a screen shot of your IDE including the error? This might help me to see what is going on.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  14. #14
    Member
    Join Date
    Apr 2009
    Posts
    31
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: fixing these two errors

    ok i attached a screen shot for the error, and both my class and main
    Attached Images Attached Images

  15. #15
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: fixing these two errors

    OK I can see your error!

    In PayCalculator you call aPayCheck.getPay()

    System.out.println("Pay: "+ aPayCheck.getPay());

    But getPay() doesn't exist in the PayCheck class.

    You have renamed getPay() to PayCheckgetPay()

    To fix the error, update the PayCalculator class with:

    System.out.println("Pay: "+ aPayCheck.[B]PayCheckgetPay()[/B]);
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  16. #16
    Member
    Join Date
    Apr 2009
    Posts
    31
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: fixing these two errors

    wow it was right in front of my face the whole time and it didnt even dawn on me about the naming of it. thanks a million for all your help.

  17. #17
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Talking Re: fixing these two errors

    Quote Originally Posted by big_c View Post
    wow it was right in front of my face the whole time and it didnt even dawn on me about the naming of it. thanks a million for all your help.
    No problem

    Glad I could help. Has this solved all your issues now?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  18. #18
    Member
    Join Date
    Apr 2009
    Posts
    31
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: fixing these two errors

    not quite its solved all the syntex stuff but now when i run it it returns pay as 0 instead of the answer to hours*hourlyWage.

  19. #19
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: fixing these two errors

    Quote Originally Posted by big_c View Post
    not quite its solved all the syntex stuff but now when i run it it returns pay as 0 instead of the answer to hours*hourlyWage.
    I knew this question was coming

    Can you please post the PayCalculator & PayCheck classes that you are now using and I will help you fix it.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  20. #20
    Member
    Join Date
    Apr 2009
    Posts
    31
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: fixing these two errors

    okay heres the right ones now
    class:
    public class PayCheck
    {
     
     
    public PayCheck(double hourlyWage,double hours)
    {
    this.PayCheck=PayCheck;
    this.hours = hours;
     
     
    }
    public int getPay()
     
    {
    if(hours>40*hourlyWage*150)
    PayCheck=;
     
    else if(hours<=40*hourlyWage)
    PayCheck=PayCheck;
     
    return PayCheck;
     
    }
    private double hourlyWage;
    public int PayCheck;
    private double hours;
    }

    Tester:
    import java.util.Scanner;
     
    /**
       This program calculates the pay of an employee.
    */
    public class PayCalculator
    {
       public static void main(String[] args)
       {
          Scanner in = new Scanner(System.in);
     
          System.out.println("Hourly wage: ");
          double hourlyWage = in.nextDouble();
     
          System.out.println("Hours worked: ");
          double hours = in.nextDouble();
     
          PayCheck aPayCheck = new PayCheck(hourlyWage, hours);
     
          System.out.println("Pay: "+ aPayCheck.getPay()) ;
       }
    }
    Last edited by big_c; April 6th, 2009 at 12:59 PM. Reason: copied wrong file

  21. #21
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: fixing these two errors

    There are a few reasons why this code did not fuction properly.

    The PayCheck value was always being passed as 0. Once that is corrected the variables need to be changed from int to double.

    Can you please explain the calculations for me? Please give me an example input for hours & hourly wage and the desired output.

    I'll post the updated code after..

    Thanks
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  22. #22
    Member
    Join Date
    Apr 2009
    Posts
    31
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: fixing these two errors

    ok for hourly wage i used 7.15 and for hours i used 40 and 50(for overtime) the output should be 286 for 40 hours and for 50 it should be 536.25 if i used the right overtime percentage

  23. #23
    Junior Member
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: fixing these two errors

    Oh I gotcha, I completely missed that line XD
    Ahh well. Well at least it's compiling the syntax now. This looks completely like an assignment I had to do for my Java course... I'm not certain as this assignment may be different, but ours had to print out the check value in a dollar format, and by the looks of what the code shows, maybe they can't enter more than 40 hours?

  24. #24
    Junior Member
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: fixing these two errors

    I'm new to this whole java thing too so, I'm just imputing my thoughts to see if I know what I'm talking about XD

    As far as the hourly wage and overtime pay. For over 40 hours shouldn't it be (40*hourlyWage)+((hours-40)*hourlyWage*1.5)

    That way you calculate the standard 40 hours worked, plus the difference of the hours worked multiplied by the wage and then calculated as time and a half?

    and if that's the case as well, shouldn't the last line in the PayCalculator class be

    System.out.printf("Pay: "+ "1.2f" + aPayCheck.getPay())

    to display it in a dollar format?

    And as the overtime, if it is time and a half, I got the result to be $393.25...

    This is a learning experience for us both =D

  25. #25
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: fixing these two errors

    Thank you for the calculations EmeraldStones. They look correct to me.

    big_c, here is the fixed code:

    public class PayCheck {
     
        public PayCheck(double hourlyWage, double hours) {
            this.PayCheck = hourlyWage;
            this.hours = hours;
     
        }
     
        public double getPay()
     
        {
          [B]  if (hours <= 40) {[/B]
    [B]
                PayCheck = (PayCheck * hours);
     
            } else if (hours > 40) {
     
                PayCheck = ((40 * PayCheck) + (hours - 40) * (PayCheck * 1.5));
     
            }[/B]
     
            return PayCheck;
        }
     
        private double hourlyWage;
        public double PayCheck;
        private double hours;
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Page 1 of 2 12 LastLast

Similar Threads

  1. Ambiguity and non-static variable reference error in java
    By jenseits in forum AWT / Java Swing
    Replies: 5
    Last Post: December 8th, 2008, 07:04 PM