Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refactoring Code

Status
Not open for further replies.

gio2888

Technical User
Oct 26, 2000
64
US
I want to combine the three if statements and put them into one function isNotEligible() and returns a boolean. The function is on the bottom, can someone help me check and see if I wrote it correctly?

//before:

double disabilityAmt(){
if (senority < 2) return 0;
if (monthsDisabled > 12) return 0;
if (isPartTime) return 0;
}

//after:

double disabilityAmt(){
if (isNotEligible())
return 0;
}


boolean isNotEligible(){
if(senority < 2 || monthsDisabled > 12 || isPartTime)
return 0;
}
 
This will not compile. You have one major mistake:
1) In java a boolean value cannot be represented by a number. It is either true or false.

Comments:
Where are your variables being stored? If they are instance variables in the class then you are fine, if not then you need to have isNotEligible() accept some parameters.

Try to fix #1 and repost the complete code if you are having any problems are you want more feedback. Wushutwist
 
I want to combine the three if statements and put them into one function isNotEligible() and returns a boolean. The function is on the bottom, can someone help me check and see if I wrote it correctly?

//before:

double disabilityAmt(){
if (senority < 2) return 0;
if (monthsDisabled > 12) return 0;
if (isPartTime) return 0;
}

//after:

double disabilityAmt(){
if (isNotEligible())
return 0;
}


boolean isNotEligible(){
if(senority < 2 || monthsDisabled > 12 || isPartTime)
return true;
}
 
Assuming that 'seniority', 'monthsDisabled' and 'isPartTime' are instance variables, then yes, your code does look correct. Looks like it's time to test. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top