Haider Mezta wrote:The attached code is simply ask you a name of any product or good and it's quantity and also the price of each item and after that it will calculate it and show you how much the total of that particular items. But every time I run the code it gives me a wrong calculation, obviously because of the "hashcode" but the problem is I don't know the exact code to put to convert the string into an integer.
OK, then what you need to do is
isolate the problem.
Right now, you have 77 lines of code that is doing all sorts of things, only ONE of which (at least as far as you know) is not working.
So, my advice: Set that program aside for now and write a new class called
NumberEntry. That class should do ONE thing, and one thing only:
Read a number from the keyboard.
You'll probably also want to print it out to make sure that it read it correctly, and you'll want to
test it with lots of different values, including invalid ones like "fred".
And don't even
think about writing another line of code in this program until your
NumberEntry class works.
Every single time, and with any input.
And when it does, it should then be a simple matter to transfer that (working) code back to your
Counter class.
Basically, you've written far too much code without testing it properly. Don't worry, it's a common mistake and we've all done it (I
still do sometimes
).
HIH
Winston