Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

# Can we simplify it any more?

krishna bethanabhotla
Greenhorn
Posts: 15
5.Simplify the following method

public static int jabberwock(boolean frumious, boolean manxome,
boolean uffish){
if (!frumious){
if (manxome) {
if (uffish){
return JUBJUB_BIRD;
}
else if (!manxome) {
return BANDERSNATCH;
}
else{
return JUBJUB_BIRD;
}
}
else {
return JUBJUB_BIRD;
}
}
else if (!uffish){
if (!manxome){
return BANDERSNATCH;
}
}
else if(!manxome){
return JUBJUB_BIRD;
}
if (!(uffish || !manxome)) {
return BANDERSNATCH;
}
return JUBJUB_BIRD;
}
public static int jabberwock(
boolean frumious,
boolean manxome,
boolean uffish) {

if (!frumious && (manxome && uffish)) {
return JUBJUB_BIRD;
} else if (!frumious && (manxome && !manxome)) {
return BANDERSNATCH;
} else if (!frumious && !uffish) {
return JUBJUB_BIRD;
} else if (!uffish && !manxome) {
return BANDERSNATCH;
} else if (!manxome) {
return JUBJUB_BIRD;
}
return JUBJUB_BIRD;
}

Michael Dunn
Ranch Hand
Posts: 4632

get rid of all the "return JUBJUB_BIRD; if blocks" and leave the final as
the default
combine the two return BANDERSNATCH; if blocks