Current location - Recipe Complete Network - Complete cookbook of home-style dishes - Please help me from java boss
Please help me from java boss

import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;

public class Recipe {

private String name; //Recipe name

private String style; //Cuisine such as: Sichuan cuisine, Hunan cuisine, etc.

private int time; / /Cooking time in minutes

private String[] food; //Ingredients

private String[] step; //Operation steps

public Recipe() {< /p>

}

public Recipe(String name, String style, int time, String[] food, String[] step) {

this.name = name;

this.style = style;

this.time = time;

this.food = food;

this.step = step;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getStyle() {

return style;

}

public void setStyle(String style) {

this.style = style;

}

public int getTime() {

return time;

}

public void setTime(int time) {

this.time = time;

}

public String[] getFood() {

return food;

}

public void setFood(String[] food) {

this.food = food;

}

public String[] getStep() {

return step;

}

public void setStep(String[] step) {

this.step = step;

< p>}

@Override

public String toString() {

String foods="";

for (String f : food) {

foods+=f+" ";

}

String steps="";

for (int i = 0 ; i < step.length; i++) {

steps += (i+1)+"."+step[i];

if(i!=step.length -1){

steps+=";";

}

}

return "Recipe name:" + name +< /p>

"\nCuisine:" + style +

"\nDuration:" + time +

"\nIngredients required:" + foods +< /p>

"\nOperation steps:" + steps;

}

public static void print(Recipe[] recipes){

for (Recipe recipe : recipes) {

System.out.println(recipe);

}

}

public static Recipe[ ] searchRecipesContainName(Recipe[] recipes, String name){

List list=new ArrayList();

for (Recipe recipe : recipes) {

p>

if(recipe.getName().contains(name)){

list.add(recipe);

}

}< /p>

return list.toArray(new Recipe[list.size()]);

}

public static Recipe[] searchRecipes(Recipe[] recipes, String style){

List list=new ArrayList();

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){

List list=new ArrayList();

for (Recipe recipe : recipes) {

if(recipe.getTime()

list.add(recipe);

}

}

return list.toArray(new Recipe[list.size()]) ;

}

public static Recipe[] searchRecipeContainsFood(Recipe[] recipes, String food){

List list=new ArrayList ();

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) {

// Store information of 5 recipes

Recipe[] recipes=new Recipe[5];

recipes[0]=new Recipe("Beef with Sauce","Home Cooking",120 ,

new String[]{

"Beef tendon",

"Soybean soy sauce",

"Yellow wine",

p>

"Rock sugar"

},

new String[]{

"Prepare the main ingredients",

"Add ingredients and simmer for two to three hours"

});

recipes[1]=new Recipe("Braised Beef","Home Cooking",120,

new String[]{

"Beef Brisket",

"Beef Tendon",

"Light Soy Sauce",

"Rock sugar"

},new String[]{

"Prepare the main ingredients",

"Add the ingredients and simmer for two to three hours"< /p>

});

recipes[2]=new Recipe("Chicken Stewed with Mushrooms","Hunan Cuisine",100,

new String[]{< /p>

"Chicken",

"Mushroom"

},

new String[]{

" Prepare the main ingredients",

"Add the ingredients and simmer for two to three hours"

});

recipes[3]=new Recipe("Ground "Three fresh foods","Sichuan cuisine",25,

new String[]{

"Eggplant",

"Chili"

},

new String[]{

"Prepare the main ingredients",

"Add the ingredients and simmer"

}) ;

recipes[4]=new Recipe("tomatoes","Hunan cuisine",20,

new String[]{

"tomatoes",< /p>

"Vida Mei Soy Sauce"

},

new String[]{

"Prepare the main ingredients",

"Add ingredients and simmer"

});

System.out.println("Find all recipes containing beef in their names:");

Recipe[] result_1 = searchRecipesContainName(recipes, "Beef");

print(result_1);

System.out.println("\nWant to find all Hunan dishes Recipe:");

Recipe[] result_2=searchRecipes(recipes,"Hunan Cuisine");

print(result_2);

System.out.println ("\nFind recipes with cooking time less than 30 minutes:");

Recipe[] result_3=searchRecipeLessThan(recipes,30);

print(result_3);

System.out.println("\nFind recipes containing tomatoes:");

Recipe[] result_4=searchRecipeContainsFood(recipes,"tomatoes");

print(result_4);

}

}