You should design input from a Scanner not to use Exceptions, nor Integer.parseInt. Please search my posts for Scanner, utility class,
there is an error somewhere. And I haven't told you where.
No. Most of those things you described do look suspicious, and I suspect some of your changes have made them worse, but I meant an error somewhere in what I wrote. It shouldn't be too difficult to find if you read the whole thread.Tushar Goel wrote: . . .
there is an error somewhere. And I haven't told you where.
. . .Are these one you talking about . . .
I suspect some of your changes have made them worse
I meant an error somewhere in what I wrote
No, that wasn't the error I meant. If you search my posts for "Prasanna Raman daft mistake" you might get closer. Hint: restrict your search to posts after 16th January this year. And before 18th January. And read the whole thread.Tushar Goel wrote: . . . category UserInput , i think now you are referring to the case in which user entered input in wrong format. . . .
Campbell Ritchie wrote:I have a different opinion of Scanner from Winston's.
You need to get to know how Scanner works and you need to let it do its work.
You do not need to handle IOExceptions because Scanner does that for you.
You do not need to deal with patterns and regexes because Scanner does that all for you.
Probably better to return an int than an Integer.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Because there are always several ways to do things in computing and there are several correct ways to do it.Winston Gutkowski wrote: . . . Very true.
![]()
Because that approach will deal with 95% of all your keyboard inputs and you can write custom classes for all the others. Scanner provides input for all the primitive types and the two BigXXX classes in the java.math package.. . . So why would you want to use one approach just for the types that Scanner provides, and a different one for all the others? . . .
I did say probably, not definitely. . .
Not necessarily; . . .
… I knew it was't true. There is no nextChar method (or at least there wasn't last time I looked). You would have to use next().charAt(0) but that is a bit like System.in.read() which I warn people against using.When I wrote: . . . Scanner provides input for all the primitive types . . .
Well done
I would call the method getInt not getNumber. I suggest you only need to print the prompt once in the getLine method
You realise that lines 20 and 21 can be swapped round without any difference in output?
I suggest you start with a single‑threaded app at present
Tushar Goel wrote:@Winston there are several correct way to achieve a common task. So both of you shared 2 separate way to achieve a common task. It is just which one is clicked... Thanks for the article.. It clear some of my doubts.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
which is why it's so important to understand WHAT you're doing (ie, the process involved), not HOW you intend to do it (the code).
But remember what I said earlier about mutable types in Maps.
date method there which returns a LocalDate object
the user name and date of birth methods don't belong in a utility class
Unless you own the website www.utility.org you should use a different package name
Remember what happens if keys in a Map change their hash codes.Tushar Goel wrote: . . .
Yes you told me about bi directional map and i am going to use Account and Customer as a attribute in this..
Look for Joda Time. It is supposed to be good, but I haven't used it myself.. . .
I am using 1.7 and do not have rights to install 8 as i am using my current employer laptop but will search for alternative..
You appear to be working on the create account method. That needs a Customer and an Account, so you will have to implement thsoe two classes before you can finish that method.. . . should i start working on customer class or anything i still missed in Bank class?
Remember what happens if keys in a Map change their hash codes.
You appear to be working on the create account method
and a"06-Jan-86"
date in dd-mm-yyyy format
That risks throwing a NumberFormatException and the idea of those loops with Scanners is to get rid of all Exceptions.
You will have difficult with asserting equals between
Why are you only using hyphen as a delimiter?
This part of the Java® Tutorials will probably help you.
If you are feeling really ambitious, you can accept words and get them with a Map
Have you confirmed that January == 1 for LocalDate?
Getting along nicely
I would have used something like [\\p] or [\\p\\s] for the separator and \\d{1,2} for the numbers. But \\W looks good. Go back to that tutorial and check.
I presume that is part of the keyboard inputs class?
private static final rather than private final static
The field might better be called DATE_REGEX;
Don't get me started about those stupid light bulbs. |