We help IT Professionals succeed at work.
Get Started

caughtSpeeding java challenge

Last Modified: 2015-11-12

I am trying below challenge


public int caughtSpeeding(int speed, boolean isBirthday) {
int result;

if(speed<=60&& isBirthday==true){
return result=0;
else {
return result=0;
else if(speed<=85){
if(speed<=61&& isBirthday==true){
return result=1;
else {
return result=1;

return result=2;

Open in new window

Expected      Run            
caughtSpeeding(60, false) → 0      0      OK         
caughtSpeeding(65, false) → 1      0      X         
caughtSpeeding(65, true) → 0      0      OK         
caughtSpeeding(80, false) → 1      1      OK         
caughtSpeeding(85, false) → 2      1      X         
caughtSpeeding(85, true) → 1      1      OK         
caughtSpeeding(70, false) → 1      1      OK         
caughtSpeeding(75, false) → 1      1      OK         
caughtSpeeding(75, true) → 1      1      OK         
caughtSpeeding(40, false) → 0      0      OK         
caughtSpeeding(40, true) → 0      0      OK         
caughtSpeeding(90, false) → 2      2      OK         
other tests

i am failing two test cases as above. Please advise
Watch Question
Top Expert 2015
This problem has been solved!
Unlock 2 Answers and 16 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE