File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Can we simplify it any more? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can we simplify it any more?" Watch "Can we simplify it any more?" New topic
Author

Can we simplify it any more?

krishna bethanabhotla
Greenhorn

Joined: Nov 30, 2004
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;
}
Answer:
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

Joined: Jun 09, 2003
Posts: 4632

haven't looked at the original code, just your answer

get rid of all the "return JUBJUB_BIRD; if blocks" and leave the final as
the default
combine the two return BANDERSNATCH; if blocks
no idea if your code (answer) is accurate

krishna bethanabhotla
Greenhorn

Joined: Nov 30, 2004
Posts: 15
Thanks Michael,
That helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we simplify it any more?
 
Similar Threads
Jabberwocky - In honour of Glorious Nonsense
Help with program: Monty Hall Problem
Can someone simplify this method?/
Query
Count Words