K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
Lovro Bajc wrote:If not, than the program would automatically correct the character. Problem starts at line 17.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Lovro Bajc wrote:If not, than the program would automatically correct the character. Problem starts at line 17.
You're right. Here's a suggestion. Instead of using a char, which doesn't have any methods, how about this instead:
Character ch = monthName.charAt(0);
?
I'll leave the rest to you; see if you can come up with a solution (you might want to read the API for java.lang.Character while you're at it).
And if you run into problems, come back.
You might also want to think about breaking out some of that code into methods as well. That switch statement, for example, is very nice; but I suspect you'll find it much more useful in a method that does something for you (daysInMonth(String month) ?).
Winston
Lovro Bajc wrote:so my task is to write a code which would ask user to input the year as integer and first three letters of the month with first being an upper case letter. Than the program would determine the number of days for given year and month.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:By the way: will ordinal() give you 1 for January or 0 for January?
Campbell Ritchie wrote:What a nice enum.
By the way: will ordinal() give you 1 for January or 0 for January?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
I presume that is because enums are bl**d* good things? I like them too.Winston Gutkowski wrote: . . . I really like enums. . . .
Campbell Ritchie wrote:I presume that is because enums are bl**d* good things?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Lovro Bajc wrote:What would than be idea behind checking if the string of entered digits contains only digits or just characters?
I know that in order to get a sub-string out you need to define range where the string starts and ends. However to include
method .isDigit does not work...
and also how to compare the entered character "-" in a string?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
While the acknowledgement is appreciated, it was Rob Spoor who showed me that technique.Winston Gutkowski wrote: . . . from the wide world of Campbell): . . .
Which is why I often tell people to write themselves utility classes.Winston Gutkowski wrote: . . .
Unfortunately, if you want to also validate that it's within a range, you have to add another loop around it. . . .
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|