String foods="";
for (String f : food) {
foods+=f+" ";
}
String steps="";
for (int i = 0; istep.length; i++) {
steps += (i+1)+"."+step[i];
if(i!=step.length-1){
steps+=";";
}
}
return "菜谱名称:" + name +
"\n菜系:" + style +
"\n时长:" + time +
"\n所需食材:" + foods +
"\n操作步骤:" + steps;
}
public static void print(Recipe[] recipes){
for (Recipe recipe : recipes) {
System.out.println(recipe);
}
}
public static Recipe[] searchRecipesContainName(Recipe[] recipes, String name){
ListRecipe list=new ArrayListRecipe();
for (Recipe recipe : recipes) {
if(recipe.getName().contains(name)){
list.add(recipe);
}
}
return list.toArray(new Recipe[list.size()]);
}
public static Recipe[] searchRecipes(Recipe[] recipes, String style){
ListRecipe list=new ArrayListRecipe();
for (Recipe recipe : recipes) {
if(recipe.getStyle().equals(style)){
list.add(recipe);
}
}
return list.toArray(new Recipe[list.size()]);
}
public static Recipe[] searchRecipeLessThan(Recipe[] recipes, int time){
ListRecipe list=new ArrayListRecipe();
for (Recipe recipe : recipes) {
if(recipe.getTime()time){
list.add(recipe);
}
}
return list.toArray(new Recipe[list.size()]);
}
public static Recipe[] searchRecipeContainsFood(Recipe[] recipes, String food){
ListRecipe list=new ArrayListRecipe();
for (Recipe recipe : recipes) {
for (String s : recipe.getFood()) {
if(s.equals(food)){
list.add(recipe);
}
}
}
return list.toArray(new Recipe[list.size()]);
}
public static void main(String[] args) {
//存储5个菜谱的信息
Recipe[] recipes=new Recipe[5];
recipes[0]=new Recipe("酱牛肉","家常菜",120,
new String[]{
"牛腱子",
"黄豆酱油",
"黄酒",
"冰糖"
},
new String[]{
"准备好主要食材",
"加入食材慢炖两至三小时"
});
recipes[1]=new Recipe("红烧牛肉","家常菜",120,
new String[]{
"牛腩",
"牛筋",
"生抽",
"冰糖"
},new String[]{
"准备好主要食材",
"加入食材慢炖两至三小时"
});
recipes[2]=new Recipe("小鸡炖蘑菇","湘菜",100,
new String[]{
"小鸡",
"蘑菇"
},
new String[]{
"准备好主要食材",
"加入食材慢炖两至三小时"
});
recipes[3]=new Recipe("地三鲜","川菜",25,
new String[]{
"茄子",
"辣椒"
},
new String[]{
"准备好主要食材",
"加入食材慢炖"
});
recipes[4]=new Recipe("西红柿","湘菜",20,
new String[]{
"西红柿",
"味达美酱油"
},
new String[]{
"准备好主要食材",
"加入食材慢炖"
});
System.out.println("找到所有名称中包含牛肉的菜谱:");
Recipe[] result_1 = searchRecipesContainName(recipes, "牛肉");
print(result_1);
System.out.println("\n希望查找所有湘菜的菜谱:");
Recipe[] result_2=searchRecipes(recipes,"湘菜");
print(result_2);
System.out.println("\n查找烹饪时长小于30分钟的菜谱:");
Recipe[] result_3=searchRecipeLessThan(recipes,30);
print(result_3);
System.out.println("\n查找包含西红柿的菜谱:");
Recipe[] result_4=searchRecipeContainsFood(recipes,"西红柿");
print(result_4);
}
}
【用java如何画蘑菇代码 java简单画图板完整代码】关于用java如何画蘑菇代码和java简单画图板完整代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- arcgis批量相交,arcgis如何批量合并相邻图斑
- 固态硬盘怎么放在前面,固态硬盘放在哪个位置
- 好玩的冒险史诗游戏,冒险好玩的游戏有哪些
- python接收函数参数 python 接收参数
- 花都专业的小程序定制开发,花都微信公众号大全
- ppt如何生成word,ppt如何生成word文档
- mysql如何在中间添加属性,mysql中添加字段的基本语法格式
- c语言的函数头文件 c语言中的头文件
- 电脑银行费率表格怎么打印,电脑银行费率表格怎么打印出来