• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

cannot find symbol error

 
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey all I am doing a program for my CS1400 class and have an error I keep getting. I have been trying to make it go away for over 2 hours now and am at a loss. Could someone please advise? I keep getting a "cannot find symbol' error for the main method's call to getTotalProductQuantityString. I know the code isn't done but I like to code a bit and compile to make sure I have no errors as I am a noob and make a ton of errors.
Thanks in advance






 
chad jensen
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry the specific line is




If i can't answer for a bit it is the anti-spam measures in the forum and I will answer when my time limit ends.
 
Marshal
Posts: 8829
631
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

1. What is an underlying logic behind having poor indentation and formatting?
2. Why do you call RetailSales a product? I think you need a Product class.

Don't know about your error, but I don't think it is the main issue at the moment.
 
chad jensen
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is the error

RetailSalesTest.java:71: error: cannot find symbol
        String productOneFinal = String.format("%s Items sold at %.2f for a total of %.2f" , product1.getTotalProductQuantityString() ,+
                                                                                                     ^
 symbol:   method getTotalProductQuantityString()
 location: variable product1 of type RetailSales
1 error


I always clean it up before I submit it. I change and clean up errors so much when coding I usually clean up indents and brackets as well as add comments as my very last step. I don't know what my final code is going to be until it is written and the program works, so it is a lot less work to indent and comment once versus multiple times.
 
Liutauras Vilda
Marshal
Posts: 8829
631
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the error better to post exact error rather than provide your interpretation. Please post full and exact error message you are getting (use copy/paste).
 
Sheriff
Posts: 17626
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try deleting the "+" sign at the end of line 71
 
chad jensen
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Deleted it and still got the error when I tried to compile. My logic is
Retail Sales involve product and I want to keep track of product sold as a result of retail sales. All product sold comes from retail sales so therefore my RetailSales class creates a record (object) of products sold. Is this a flawed line of reasoning?
 
Liutauras Vilda
Marshal
Posts: 8829
631
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chad jensen wrote:Deleted it and still got the error when I tried to compile.

And what this time was? Have you noticed from previous error message there were exact line number where problem existed. You should see something similar this time too.
 
chad jensen
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


exact same thing
 
Liutauras Vilda
Marshal
Posts: 8829
631
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And how those lines look after you fixed as per Junilu suggestion?
 
Junilu Lacar
Sheriff
Posts: 17626
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just as a sanity check, change the method name to foo() and change the usages of the method name to foo, too.  If you don't get a compiler error when you do that, then there was something different in the name you declared and the name you typed in when you tried to call the method.
 
author
Posts: 23942
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Compiles fine for me. Perhaps, you have a file corruption somewhere. Try deleting your class files and compiling everything again.

Henry
 
chad jensen
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The other method calls in the statement don't have issues. In fact, I replaced the problem statement with the getProductPrice method call and everything worked like it should have.
 
chad jensen
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:
Compiles fine for me. Perhaps, you have a file corruption somewhere. Try deleting your class files and compiling everything again.

Henry



Thank you so much.
That was it, I was tearing my hair out trying to figure it out. You're a lifesaver.
 
chad jensen
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, it compiled then when I tried to run it I got the same error. I will try to delete the files then copy them as new files. I did that and found I had another copy of the class files in another folder so I deleted those too. Now everything works great. Thank you once again everyone for your input.
 
Henry Wong
author
Posts: 23942
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If classes in different locations are affecting you, you probably have a classpath set. Since you only have two classes, and not using packages, it is probably a good idea to not set a classpath.

Henry
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chad jensen wrote:I usually clean up indents ...as my very last step. I don't know what my final code is going to be until it is written and the program works, so it is a lot less work to indent and comment once versus multiple times.


My guess is that if you indented it correctly as you wrote it, you'd have a lot fewer errors to fix, creating less overall work for you.  A decent editor will even do all the indenting for you...
 
chad jensen
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:

chad jensen wrote:I usually clean up indents ...as my very last step. I don't know what my final code is going to be until it is written and the program works, so it is a lot less work to indent and comment once versus multiple times.


My guess is that if you indented it correctly as you wrote it, you'd have a lot fewer errors to fix, creating less overall work for you.  A decent editor will even do all the indenting for you...



not really, because I don't look at code as a whole I am not that good yet I just deal with the parts that I am working on at the time. I have had maybe 5 enum errors since I started coding, which are caused by missing or extra brackets. My biggest problem is the horrible way the book I am learning from names all the variables, classes, methods etc. It names them all the same with no differentiating on what points to where. My biggest issue is knowing if x points to x method or x variable or x class or x object and 2/3 of the way through the class I finally figured out the main method is like a conductor and when it "calls" a get method it is actually telling the object to perform the actions inside the method named "getxxxx" inside the object. I thought the get method was executed and forced the return of the value to the main method without a call when ever a new instance of a class is created up until now. I have tried to have a tutor explain it to me and he just told me, "Just do it like it is shown in the example." The book is definitely not written for a new programmer. This book is a nightmare to learn from. And our teacher is requiring us to use JGrasp to code with. I am not sure why but it does indent when you hit enter but like I said before I change the code so much the indents end up getting messed up. I don't need to depend on my indents to read my own code though. I can read it better than the book's code with all the proper indents and format.
 
Henry Wong
author
Posts: 23942
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chad jensen wrote: I don't need to depend on my indents to read my own code though. I can read it better than the book's code with all the proper indents and format.



As a side note, the indents are not just for you... You will also be judged on it. In the assignments that you turn in. Over your shoulder as you do assignments during job interviews. Code (including interim code) that you share with your colleagues. etc.

Fair or unfair. It is like a chef that makes a great meal, but won't get the job because he/she makes a mess in the kitchen.  Or in other words, it is probably a real good idea to get into good habits, before you can develop bad ones.

Henry
 
Rancher
Posts: 5007
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also posted at: http://www.dreamincode.net/forums/topic/402275-need-help-with-an-issue-that-is-stumping-me/
 
Marshal
Posts: 78656
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chad jensen wrote:. . . I don't look at code as a whole I am not that good yet

I am afraid I agree with the other people who have mentioned indentation. Why make the code harder for you to read?

. . . the horrible way the book I am learning from names all the variables, classes, methods etc. . . . The book is definitely not written for a new programmer.

Which book is it, so we can consider avoiding it?

. . . requiring us to use JGrasp to code with. . . .

I don't like requiring people to use a particular product like that, and I haven't used JGrasp for a very long time, but I have only good memories of it.
 
chad jensen
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

chad jensen wrote:. . . I don't look at code as a whole I am not that good yet

I am afraid I agree with the other people who have mentioned indentation. Why make the code harder for you to read?
Is this better for fromat? this is the final product and how our instructor wants us to format it.

. . . the horrible way the book I am learning from names all the variables, classes, methods etc. . . . The book is definitely not written for a new programmer.

Which book is it, so we can consider avoiding it?
Deitel How to program 10th edition. People in this forum would probably be able to make sense of the book but for a total noob, the wording, the choice of variable names and the lack of thorough explanation makes it so hard to learn anything.

. . . requiring us to use JGrasp to code with. . . .

I don't like requiring people to use a particular product like that, and I haven't used JGrasp for a very long time, but I have only good memories of it.


I wasn't bad mouthing JGrasp I just have played around with Netbeans and it is so much easier to use. Maybe that's why our professor didn't want us to use another compiler is for the same reason we have to do math long hand is so we can know it and learn it better instead of having the program do most of the work for us.

Since people were helping me with my formatting, this is my final program that I will turn in. This is the format the instructor wants us to complete our assignments in. What do you all think of comments and did I screw up on an indent anywhere?
Thanks all for the time you spend helping others.

 
chad jensen
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just caught the end switch loop bracket and corrected it.
 
Campbell Ritchie
Marshal
Posts: 78656
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that's better. Indentation correct, but I can still see things wrong even without reading the whole code.
  • 1: The comments before the class and methods are the wrong format. They shou‍ld be /**...documentation comments*/
  • 2: Comments like // creates instance variables are a waste of space.
  • 3: Only use \n if you have been asked for the LF character. Especially after printf. After printf us %n instead.
  • 4: Why have you got product1, product2, etc? That is crying out for an array. Don't you know how to write arrays yet?
  • At a closer look, probably the most serious thing is that you have so much code in the main method The main method shou‍ld be one statement long. All that code shou‍ld be moved into separate methods. That will also sort out the problem of having loops inside loops and multiple break;s which make the flow of control difficult to follow.
    Why are you using option panes for keyboard input? That is a very old‑fashioned programming style which has been largely superseded by Scanner.
    Why are you converting the prices to Strings?
    Even though you broke the longer statements (lines 170‑178) into multiple lines, you haven't been aggressive enough breaking lines. They shou‍ld be much shorter. Look at line 128.
    Also in line 128: use single spaces on each side of operators; you have double spaces after the = sign.
    The first class you wrote is a lot better, with simple methods and straightforward methods
     
    chad jensen
    Greenhorn
    Posts: 29
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Norm Radder wrote:Also posted at: http://www.dreamincode.net/forums/topic/402275-need-help-with-an-issue-that-is-stumping-me/



    Yes I did. I was frustrated with this and was not sure which forum was more active so I posted in the top two search results. This forum was by far more active so I chose this one to participate in this one.
     
    Liutauras Vilda
    Marshal
    Posts: 8829
    631
    Mac OS X VI Editor BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    There is nothing wrong to post in multiple forums same problem as long as you let every part to know that you did so.
    The main reason for that is, so the people wouldn't answer questions which might have been answered already.

     
    Junilu Lacar
    Sheriff
    Posts: 17626
    300
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    chad jensen wrote:What do you all think of comments and did I screw up on an indent anywhere?


    No, your indentation actually looks good. The comments, not so much.

    Comments like the ones you've written are redundant; they don't say anything more than what the code already does. As I just said in another thread, you might as well be walking around announcing each step you make: "Putting my left foot forward, putting my right foot forward, left foot forward, right foot forward..." which is kind of silly if you think about it.

    The one comment that says "//creates instance variables" isn't even technically correct. You are declaring variables there.  

    The comment at the end of line 160 is also incorrect. A switch statement is not a loop as your comment claims.

    The comments that come after closing braces like "// end main method" and "//end RetailSalesTest" are again redundant and unnecessary. If you have so much code between the opening and closing braces of a code block that you need those kinds of comments to help you see which block a closing brace terminates, then you have way too much code between the braces and you should break it down into smaller chunks of functionality. If you indent and align your code properly and have reasonably-sized methods (20-30 lines on average for beginners, 1-5 lines on average for experienced programmers), where a block of code starts and ends should be easy to discern.
     
    Junilu Lacar
    Sheriff
    Posts: 17626
    300
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    chad jensen wrote:...did I screw up on an indent anywhere?


    Actually, the closing brace on line 160 should be aligned with the opening brace on line 139. As posted, that closing brace is one level of indentation too deep.

    Also, you should be consistent with spacing.  Your while statements have a space between the "while" and the opening parenthesis (lines 86 & 98 for example) but some of your if statements don't have a space (lines 108, 167, 188) while others do (line 122). Be consistent and separate the control structure key word (while, if, switch, for) and the opening parenthesis that follows it with a space. It's easier to read your code that way. IDEs that can format your code automatically like NetBeans, Eclipse, and IntelliJ IDEA will do that for you.
     
    Liutauras Vilda
    Marshal
    Posts: 8829
    631
    Mac OS X VI Editor BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Junilu Lacar wrote:(20-30 lines on average for beginners, 1-5 lines on average for experienced programmers)


    It is a very nice allegory, which demonstrates that the more experienced you are, the more simplicity you require.
     
    Junilu Lacar
    Sheriff
    Posts: 17626
    300
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Liutauras Vilda wrote:

    Junilu Lacar wrote:(20-30 lines on average for beginners, 1-5 lines on average for experienced programmers)


    It is a very nice allegory, which demonstrates that the more experienced you are, the more simplicity you require.


    Kent Beck, the co-author of JUnit and pioneer of Extreme Programming and concocter of the Four Rules of Simple Design supposedly writes most of his methods as one-liners. Apparently, he extracts and composes methods to the extreme.
     
    chad jensen
    Greenhorn
    Posts: 29
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Campbell Ritchie wrote:Yes, that's better. Indentation correct, but I can still see things wrong even without reading the whole code.

  • 1: The comments before the class and methods are the wrong format. They shou‍ld be /**...documentation comments*/
  • I tried a different format on those comments and my grade went from a 100 to an 88 because the beginning comments weren't in the format like they are in this program

    Campbell Ritchie wrote:

  • 2: Comments like // creates instance variables are a waste of space.
  • I agree and thought that right from the beginning but once again the teacher is super picky and the slightest mistake will bring my grade down considerably so I have to jump through his hoops while in his class.

    Campbell Ritchie wrote:

  • 3: Only use \n if you have been asked for the LF character. Especially after printf. After printf us %n instead.
  • 4: Why have you got product1, product2, etc?
  • Not sure the difference between the 2 but I will have to look more into it. The book uses the\n that is why I did but I will have to figure out the difference so I will know when the correct time to use one or the other.

    Campbell Ritchie wrote: That is crying out for an array. Don't you know how to write arrays yet?

    unfortunately, no we haven't gotten to arrays yet I understand the concept I just don't know the syntax and using them will make coding easier but we aren't there yet.

    Campbell Ritchie wrote:At a closer look, probably the most serious thing is that you have so much code in the main method The main method shou‍ld be one statement long. All that code shou‍ld be moved into separate methods. That will also sort out the problem of having loops inside loops and multiple break;s which make the flow of control difficult to follow.

    They wanted us to use the different loops as part of the assignment so I guess I should have put them in different classes I don't understand how you can have just a single statement in the main method. How do you use classes to create objects if you don't have your instance variables in the main method? How do you create objects and call them to print if you don't have that code in the main method. Even the book we are learning from has more code in the main method than in the classes. I am not saying it isn't possible I am just saying my inexperience makes it so I can't envision how it's done.I do have to use the switch and sentinel controlled while loop as part of the assignment that is why I used them.

    Campbell Ritchie wrote:
    Why are you using option panes for keyboard input? That is a very old‑fashioned programming style which has been largely superseded by Scanner.

    GUI is old fashioned? That surprises me since 99 percent of what people do with computers is GUI. I always thought GUI was newer than CLI.

    Campbell Ritchie wrote:
    Why are you converting the prices to Strings?

    Just trying to get it as a single message as a variable value so it is easier to call out for JOptionPane. Also I am not sure how to use int value in JOptionPane so I had to convert it all to a string to be able to plug it into JOptionPane

    Campbell Ritchie wrote:Even though you broke the longer statements (lines 170‑178) into multiple lines, you haven't been aggressive enough breaking lines. They shou‍ld be much shorter. Look at line 128.
    Also in line 128: use single spaces on each side of operators; you have double spaces after the = sign.
    The first class you wrote is a lot better, with simple methods and straightforward methods

    Thanks for the link I will have to check it out.
    This class started out enjoyable and I do enjoy the coding but the teacher is so nit picky he takes the fun out of it sometimes. I work for hours to get a program wrote and he gives me an 88 because I have the wrong header format. It is discouraging sometimes. I do like coding and would like to continue after the class ends though. The support you guys give makes me feel better about stay with it.
    Thank you
     
    Campbell Ritchie
    Marshal
    Posts: 78656
    374
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    chad jensen wrote:. . . I tried a different format on those comments and my grade went from a 100 to an 88 because the beginning comments weren't in the format like they are in this program

    I am trying to produce a reply which I can actually post on a family website.

    . . . The book uses the\n . . .

    Lots of books use \n which is the correct line end for a Unix/Linux box, but isn't right on Windows. Most applications can correct for the error, but a few, e.g. MS NotePad get confused.

    . . . unfortunately, no we haven't gotten to arrays . . .

    Unfortunately you are stuck with the five statements, then. You will probably learn arrays soon; they are very basic. Then you will see how much easier it would have been with an array.

    I don't understand how you can have just a single statement in the main method.

    You quoted what I wrote earlier. In that quote, which I have here removed, you will find a link.

    . . . if you don't have your instance variables in the main method? . . .

    You can't have anything instance in the main method. I think the link I quoted will give you the answer. Here it is again.

    . . . GUI is old fashioned? . . .

    I didn't say GUIs are old‑fashioned. I said option pane is an old‑fashioned form of keyboard input.

    . . . I am not sure how to use int value in JOptionPane so I had to convert it all to a string to be able to plug it into JOptionPane

    Try the + operator.
    "chad jensen has " + 999999 + " posts on CodeRanch."

    . . . Thank you

    That's a pleasure

    [edit]I also corrected your quote tags.
     
    Where does a nanny get ground to air missles? Protect this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic