Hi, this week in class we're working with LinkedLists and while my program runs when I use user ID as an int, my sentinel value "000" ends the program whenever an ID of "0", "00" or "000" is entered. I realised that 0 = 00 = 000, so to fix that I changed the ID from int value to string value. Now however, my code doesn't recognise any input and always outputs "No such customer".
I'm sure the issue I'm having is super simple. Also, if there's anything that I could do to fix/clean-up the code as I'm still learning Java. If possible, please explain why you do certain things so I can learn instead of just copy/pasting solutions, thanks!
Thanks, that fixed the sentinel value issue! However, whenever I enter any other value for the ID, it's still returning a null match (presumably) as "No such customer" keeps being printed.
Beware of nextLine() on a Scanner object. A lot of people have problems because they don’t call nextLine often enough. You may have problems if your input is a line like
The issue isn't the input not being read, but rather I think my LinkedList matching code being wrong.
All the examples we were giving were doing with int but I presumed it'd work for String as well, but that seems to not be the case, and I'm lost as to why.
EDIT: Solved it cause I'm an idiot and didn't update the customer.matches();
Thanks to the help above for the .equals() for strings!
One simple debugging technique is to put a bunch of System.out.println() statements in your code.
If you think the problem is in that method, do something like this:
You can then see EXACTLY what this method is doing...when you enter/leave it, how many times it loops, if it ever finds a match...Once you figure this out, you may learn that your matches() method doesn't return the correct value...or maybe your loop doesn't work right...but in any case, it helps you focus in on where the problem REALLY is.
Post by:autobot
Screaming fools! It's nothing more than a tiny ad:
a bit of art, as a gift, that will fit in a stocking