Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fundamental coding help
#6
Okay this is getting pretty petty of me, but I keep getting the impression that my approach isn't proper enough. It just seems somehow messy.

 Spoiler

I have a favor though, regarding this problem:
Quote:Given 3 int values, a b c, return their sum. However, if any of the values is a teen -- in the range 13..19 inclusive -- then that value counts as 0, except 15 and 16 do not count as a teens. Write a separate helper "public int fixTeen(int n) {"that takes in an int value and returns that value fixed for the teen rule. In this way, you avoid repeating the teen code 3 times (i.e. "decomposition"). Define the helper below and at the same indent level as the main noTeenSum().

noTeenSum(1, 2, 3) → 6
noTeenSum(2, 13, 1) → 3
noTeenSum(2, 1, 14) → 3

The solution should be simple enough, but I can't seem to "call" the n from the fixTeen block to the main block to use. Also, I may not be thinking straight but how do I filter so that the outcome n satisfies certain conditions? I have been doing something along the lines of conditionals:
Code:
public int fixTeen(int n){
  if( (n>=13) && (n<=19) && (n != 15) && (n != 16) )
  return n;
}
But I can't test if it works correctly because of the problem above.
Reply


Messages In This Thread
Fundamental coding help - by Kalovale - 2010-10-28, 04:38 AM
Fundamental coding help - by Fiel - 2010-10-28, 08:24 AM
Fundamental coding help - by Kalovale - 2010-10-28, 10:07 AM
Fundamental coding help - by Eos - 2010-10-28, 10:22 AM
Fundamental coding help - by Fiel - 2010-10-28, 10:38 AM
Fundamental coding help - by Kalovale - 2010-10-28, 12:16 PM
Fundamental coding help - by Nikkey - 2010-10-28, 12:49 PM
Fundamental coding help - by Kalovale - 2010-10-28, 12:59 PM
Fundamental coding help - by Nikkey - 2010-10-28, 01:06 PM
Fundamental coding help - by Kalovale - 2010-10-28, 01:09 PM
Fundamental coding help - by XTOTHEL - 2010-10-28, 02:47 PM
Fundamental coding help - by Nikkey - 2010-10-28, 03:06 PM
Fundamental coding help - by Dusk - 2010-10-28, 03:17 PM
Fundamental coding help - by Stereo - 2010-10-28, 03:45 PM
Fundamental coding help - by Kalovale - 2010-10-29, 10:50 AM
Fundamental coding help - by Spaz - 2010-10-29, 02:41 PM
Fundamental coding help - by Fiel - 2010-10-29, 04:07 PM
Fundamental coding help - by Stereo - 2010-10-30, 09:46 AM
Fundamental coding help - by Russt - 2010-10-30, 10:34 AM
Fundamental coding help - by Kalovale - 2010-11-03, 12:50 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)