第1个回答 2016-01-06
package fac;
public class FruitGardener{
public static Fruit factory(String which)throws Exception{
if(which.equalsIgnoreCase("apple")){
return new Apple();
}else if(which.equalsIgnoreCase("strawberry")){
return new Strawberry();
}else if (which.equalsIgnoreCase("grape")){
return new Grape();
}else{
throw new Exception("Bad fruit request");
}本回答被网友采纳