
212 第
7
章
update code
更新
Recipes
项目
现在你已经学习了如何使用默认参数值以及重载方法,让我们
更新一下
Recipes
项目代码。
请更新Recipes.kt文件中的代码版本,使其与如下代码一致(更
改的代码以粗体显示):
data class Recipe(val title: String,
val mainIngredient: String,
val isVegetarian: Boolean = false,
val difficulty: String = "Easy") {
}
class Mushroom(val size: Int, val isMagic: Boolean) {
constructor(isMagic_param: Boolean) : this(0, isMagic_param) {
//Code that runs when the secondary constructor is called
}
}
fun findRecipes(title: String = "",
ingredient: String = "",
isVegetarian: Boolean = false,
difficulty: String = "") : Array<Recipe> {
//Code to find recipes
return arrayOf(Recipe(title, ingredient, isVegetarian, difficulty)) ...