aspose file tools*
The moose likes Cattle Drive and the fly likes Help understanding nitpick on Java-4a (Say) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Help understanding nitpick on Java-4a (Say)" Watch "Help understanding nitpick on Java-4a (Say)" New topic
Author

Help understanding nitpick on Java-4a (Say)

Daniel Loranz
Ranch Hand

Joined: Jun 17, 2008
Posts: 41
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!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9052
    
  12
How many string arrays do you have? Two of them should be enough.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1364
    
  17
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?
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
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.
 
Consider Paul's rocket mass heater.
 
subject: Help understanding nitpick on Java-4a (Say)