Ashutosh Panda
12/02/2019, 12:59 PMgian
12/02/2019, 1:13 PMAshutosh Panda
12/02/2019, 1:15 PMclass Spice(var Spicename:String,var Spiceness:String="Mild"){
init{
println("Spice name is ${Spicename)} and Spiciness is ${Spiceness}")
}
}
val s= listOf<Spice>()
gian
12/02/2019, 1:17 PMAshutosh Panda
12/02/2019, 1:17 PMCreate a new class, Spice.
Pass in a mandatory String argument for the name, and a String argument for the level of spiciness where the default value is mild for not spicy.
Add a variable, heat, to your class, with a getter that returns a numeric value for each type of spiciness.
Instead of the list of spices as Strings you used earlier, create a list of Spice objects and give each object a name and a spiciness level.
Add an init block that prints out the values for the object after it has been created. Create a spice.
Create a list of spices that are spicy or less than spicy. Hint: Use a filter and the heat property.
Because salt is a very common spice, create a helper function called makeSalt().
gian
12/02/2019, 1:24 PMval heat: Int
get() {
// implement your logic
}
Ashutosh Panda
12/02/2019, 1:24 PMgian
12/02/2019, 1:42 PMlistOf(1, 2, 3)