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 wrote:Deleted it and still got the error when I tried to compile.
Henry Wong wrote:
Compiles fine for me. Perhaps, you have a file corruption somewhere. Try deleting your class files and compiling everything again.
Henry
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.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
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...
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.
I am afraid I agree with the other people who have mentioned indentation. Why make the code harder for you to read?chad jensen wrote:. . . I don't look at code as a whole I am not that good yet
Which book is it, so we can consider avoiding 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.
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.. . . requiring us to use JGrasp to code with. . . .
Campbell Ritchie wrote:
I am afraid I agree with the other people who have mentioned indentation. Why make the code harder for you to read?chad jensen wrote:. . . I don't look at code as a whole I am not that good yet
Is this better for fromat? this is the final product and how our instructor wants us to format it.
Which book is it, so we can consider avoiding 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.
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.
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.. . . requiring us to use JGrasp to code with. . . .
Norm Radder wrote:Also posted at: http://www.dreamincode.net/forums/topic/402275-need-help-with-an-issue-that-is-stumping-me/
chad jensen wrote:What do you all think of comments and did I screw up on an indent anywhere?
chad jensen wrote:...did I screw up on an indent anywhere?
Junilu Lacar wrote:(20-30 lines on average for beginners, 1-5 lines on average for experienced programmers)
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.
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 programCampbell 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 should be /**...documentation comments*/
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:
2: Comments like // creates instance variables are a waste of space.
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:
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?
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: That is crying out for an array. Don't you know how to write arrays yet?
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:At a closer look, probably the most serious thing is that you have so much code in the main method The main method should be one statement long. All that code should 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.
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 using option panes for keyboard input? That is a very old‑fashioned programming style which has been largely superseded by Scanner.
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 JOptionPaneCampbell Ritchie wrote:
Why are you converting the prices to Strings?
Thanks for the link I will have to check it out.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 should 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 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
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.. . . The book uses the\n . . .
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.. . . unfortunately, no we haven't gotten to arrays . . .
You quoted what I wrote earlier. In that quote, which I have here removed, you will find a link.I don't understand how you can have just a single statement 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.. . . if you don't have your instance variables in the main method? . . .
I didn't say GUIs are old‑fashioned. I said option pane is an old‑fashioned form of keyboard input.. . . GUI is old fashioned? . . .
Try the + operator.. . . 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
That's a pleasure. . . Thank you
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
|