# teenSum java challenge

Hi,
I am trying below challenge

http://codingbat.com/prob/p178728

I tried as  below
``````public int teenSum(int a, int b) {
int sum =a+b;

if(a==13||a==13||a==14||a==15||a==16||a==17||a==18||a==19||b==13||b==14||b==15||b==16||b==17||b==18||b==19)

{
return 19;
}

return a+b;

}
``````

I am getting below result

Expected      Run
teenSum(3, 4) → 7      7      OK
teenSum(10, 13) → 19      19      OK
teenSum(13, 2) → 19      19      OK
teenSum(3, 19) → 19      19      OK
teenSum(13, 13) → 19      19      OK
teenSum(10, 10) → 20      20      OK
teenSum(6, 14) → 19      19      OK
teenSum(15, 2) → 19      19      OK
teenSum(19, 19) → 19      19      OK
teenSum(19, 20) → 19      19      OK
teenSum(2, 18) → 19      19      OK
teenSum(12, 4) → 16      16      OK
teenSum(2, 20) → 22      22      OK
teenSum(2, 17) → 19      19      OK
teenSum(2, 16) → 19      19      OK
teenSum(6, 7) → 13      13      OK
other tests
OK

how to  improve my approach and design of this challenge. How do i make a graphical venn or some other relevant diagram to design it before writing single line of code to decide best strategy?
LVL 7
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
return (13<=a&&a<=19)||(13<=b&&b<=19)?19:a+b;
Author Commented:
How to use mothod approach
Commented:
``````public int teenSum(int a, int b) {
if(isLuckyRange(a, b)){
return 19;
}
return a + b;
}

private boolean isLuckyRange(int a, int b){
return (a >= 13 && a <=19) || (b >= 13 && b <= 19);
}
``````

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
13<=a&&a<=19

above solution how the values like 14, 15, 16, 17, 18 checked?
Author Commented:
i got it. you are checking if in between 13, 19 both includinded for both a and b which is more refined approach than mine
Commented:
13<=14 is true and 14<=19 is true
Information Technology SpecialistCommented:
Slight modification to gurpsbassi's solution using a method -
public int teenSum(int a, int b) {
return isLuckyRange(a, b) ? 19 : a + b;
}

private boolean isLuckyRange(int a, int b){
return (a >= 13 && a <=19) || (b >= 13 && b <= 19);
}
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.