• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Help understanding nitpick on Java-4a (Say)

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a working version of Java-4a which I think solves the problem fairly nicely. However, the JR Sheriff keeps hinting that I am duplicating something, which I cannot figure out.

I have ...

1 - Build needed string arrays.
2 - Check if number is in allowed range.
3 - Check if number is between 0 and 19 (inclusive)
3a - do stuff to get output for number from 0 to 19 (one line of code)
3b - else do stuff to get output for number from 20 to 99 (one line of code)

I keep thinking that 0 to 19 needs to be handled differently than 20 to 99. After all, 0 to 19 is where you have to output things like "seventeen" etc rather than "thirty-one".

However, I keep getting hints that somehow there are elements in steps 3a and 3b that are common, and I am not seeing how.

Perhaps I am misunderstanding the nitpicks. Not sure if this helps anyone help me, but the nitpicks have been ...

"Rather than adding another (duplicate) array, I was trying to suggest that you take tens[inputNumber / 10] and print it outside this if/else block."

and

"Any way to avoid printing tens[tensDigit] twice??"

and

"Notice how the first part of your if and else are the same?"

I'm really missing something. Any help would be greatly appreciated.

Thanks!
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How many string arrays do you have? Two of them should be enough.
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there Daniel,

From the comments it looks like you might have run into a case where you are doing a certain thing whether or not a condition is met.

For example, if it is a weekday, you eat dinner, else... if it is the weekend, you do other stuff and eat dinner. In such cases, eating dinner doesn't have to go inside the if/else at all.

If you put eating dinner inside the if/else, you have to print it twice. If you stick it right before or right after the if/else, you get the benefit of eating dinner both on weekends and on weekdays, but only have to print it once.

... make sense in a weird sort of twisted way?
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Katrina Owen:
[...]

For example, if it is a weekday, you eat dinner, else... if it is the weekend, you do other stuff and eat dinner. In such cases, eating dinner doesn't have to go inside the if/else at all.

If you put eating dinner inside the if/else, you have to print it twice. If you stick it right before or right after the if/else, you get the benefit of eating dinner both on weekends and on weekdays, but only have to print it once.

... make sense in a weird sort of twisted way?




I love this.
 
reply
    Bookmark Topic Watch Topic
  • New Topic