• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Help understanding nitpick on Java-4a (Say)

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • 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: 9099
12
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic