Liutauras Vilda wrote:Welcome to the ranch,
Ronnie,Kevin,
On line 27 and line 30 you declare userName and passWord once again as local variables, hence not assigning values to instance variables of the same names. Just remove String data type declaration from line 27 and 30 and supposed to be "ok" on this matter.
There might be more mistakes, so report to us in case of that. However, there are more things to improve, but since this program reminds me one of mine first programs, I think it isn't that bad
Campbell Ritchie wrote:Welcome to the Ranch again
Don't create multiple Scanners to read from System.in. Use one Scanner per application for System.in and never close it. Beware of Scanner#nextLine. What does your book say it does?
Please explain why you have password[0] and password[1] in an array; I can't see why you have that feature.
That is a lot better than in some books I have seen. Another way to put it is that it reads the remainder of the current line. See the official documentation. If you look here, you will see you can get nasty problems if you get the previous line.Kevin O'Sullivan wrote:. . . nextLine(); reads in input from user and positions cursor on the next line.
I don't like parallel arrays, in case you get them out of synch. Can you create a NameAndPassword class which will encapsulate both?As for your other question, I wanted password[0] to match up name[0] . . .
Kevin O'Sullivan wrote:That worked, much appreciated thanks, they're indeed loads of mistakes, for instance when I press 0 to exit the program, the wrongPassWord() method and exit method are called which is not what I want, how can I fix this? or can you at least put me on the right track?
All things are lawful, but not all things are profitable.
Campbell Ritchie wrote:
Kevin O'Sullivan wrote:Can you create a NameAndPassword class which will encapsulate both?
You realise that non‑training apps never store a password?
Thanks for the suggestion, I'll look into that, not to sure how to do it.
On your second do you mean I should be storing the usernames and passwords externally?
Knute Snortum wrote:
Kevin O'Sullivan wrote:That worked, much appreciated thanks, they're indeed loads of mistakes, for instance when I press 0 to exit the program, the wrongPassWord() method and exit method are called which is not what I want, how can I fix this? or can you at least put me on the right track?
Here is some of your code properly indented:
Can you see the problem now? Tip: breaks are not what you want here.
All things are lawful, but not all things are profitable.
No.Kevin O'Sullivan wrote:. . . do you mean I should be storing the usernames and passwords externally?
Consider Paul's rocket mass heater. |