Your question is Debug and Optimize Code Logic. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
Accenture Federal Services builds a benefits-eligibility screening tool for a federal program. A caseworker reported that veterans are showing up under the wrong eligibility tier even when the veteran flag is set correctly. Here is the method in question:
public class EligibilityEvaluator {
public String determineTier(int income, int dependents, boolean isVeteran) {
String tier = "NONE";
if (isVeteran = true) {
tier = "PRIORITY";
}
if (income < 30000) {
tier = "TIER_1";
}
if (income <= 30000) {
tier = "TIER_1";
}
if (income > 30000 && income < 60000) {
tier = "TIER_2";
}
if (income >= 60000) {
tier = "TIER_3";
}
if (dependents > 3) {
tier = "TIER_1";
}
return tier;
}
}
First, what does determineTier(30000, 1, false) return? Then explain the logic bugs you can find in this method, including anything that means veteran status never actually affects the result, and how you would restructure it to be both correct and easier to reason about.