withoutDoubles challenge

Hi,

I am working on below challenge
http://codingbat.com/prob/p115233

I tried my code as below
public int withoutDoubles(int die1, int die2, boolean noDoubles) {

if(noDoubles==false){
return die1+die2;
}
  
  else if(die1==die2){
  return die1+die2+1;
  
  }
  else
  return 1;
}

Open in new window


I am getting below result
Expected      Run            
withoutDoubles(2, 3, true) → 5      1      X         
withoutDoubles(3, 3, true) → 7      7      OK         
withoutDoubles(3, 3, false) → 6      6      OK         
withoutDoubles(2, 3, false) → 5      5      OK         
withoutDoubles(5, 4, true) → 9      1      X         
withoutDoubles(5, 4, false) → 9      9      OK         
withoutDoubles(5, 5, true) → 11      11      OK         
withoutDoubles(5, 5, false) → 10      10      OK         
withoutDoubles(6, 6, true) → 7      13      X         
withoutDoubles(6, 6, false) → 12      12      OK         
withoutDoubles(1, 6, true) → 7      1      X         
withoutDoubles(6, 1, false) → 7      7      OK         
other tests
OK         

how to  improve my approach, results and design of this challenge. How do i make a graphical venn or flow chart or some other relevant diagram to design it before writing code to decide best strategy?
 Please advise
LVL 7
gudii9Asked:
Who is Participating?
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.

krakatoaCommented:
iirc, you already did this challenge quite a while ago.

?
ozoCommented:
public int withoutDoubles(int die1, int die2, boolean noDoubles) {
  return noDoubles&&die1==die2?
         die1+die2%6+1
         :
         die1+die2;        
}

Experts Exchange Solution brought to you by

Your issues matter to us.

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

Start your 7-day free trial
gudii9Author Commented:
public int withoutDoubles(int die1, int die2, boolean noDoubles) {

if(noDoubles && die1==die2){
  return die1+die2%6+1;
}
  
 
  
  
  else
  return die1+die2; 
}

Open in new window



above passed all cases as you mentioned.

My question is can i write as below as well?

public int withoutDoubles(int die1, int die2, boolean noDoubles) {

if(noDoubles && die1==die2){
  return die1%6+die2+1;
}
  
 
  
  
  else
  return die1+die2; 
}

Open in new window



which is best approach ?

die1%6 approach or die1%6 approach?
does it vary results if i change approach to  die1%6
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

gudii9Author Commented:
public int withoutDoubles(int die1, int die2, boolean noDoubles) {

if(noDoubles && die1==die2){
  return die1%6+die2+1;
}
  
 
  
  
  else
  return die1+die2; 
}

Open in new window


apparently above also passed all tests??
ozoCommented:
die1%6 approach or die1%6 approach?
looks the same to me
gudii9Author Commented:
wrapping around to 1 if its value was 6.

but challenge did not mention die1 or die2? i wonder which one to take ideally?
gudii9Author Commented:
withoutDoubles(6, 5, true) →

withoutDoubles(6, 5, false) →

withoutDoubles(5, 6, true) →

withoutDoubles(5, 6, false) →

what results we get in above 4 cases ?

please advise
ozoCommented:
In above 4 cases, the two dice do not show the same value, so just return the sum.
gudii9Author Commented:
oops i missed the point that both dies needs to be equal to do
die1%6+die2+1
then it really does not matter die1%6 or die2%6.

How to read and comprehend challenge correctly first time itself like you people?
it is some times taking many times of going over to understand the depth and width of the challenge?
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

From novice to tech pro — start learning today.