Question: Need help implementing this using Kotlin/java This is what I currently have so far. class Function { // data member obj1: Int? obj2: String? cond:

Need help implementing this using Kotlin/java

This is what I currently have so far.

class Function { // data member obj1: Int? obj2: String? cond: (val1: Int, val2: Int) -> Boolean // member function fun compareFunction(): Int { //the rest goes here goes here??? } } //This should be the main function for the program 
fun main(args: Array) { // obj object of Function class val obj = Function() println("${obj.compareFunction()}") }
 Need help implementing this using Kotlin/java This is what I currently have } fun main(args: Array) { // create obj object of Example class val obj = Example() println("${obj.calculateSquare()}") }

[Optional Type and Higher Order Function] You will implement a higher order function to compare two objects (of Int and String type) by applying a user-defined condition (via a lambda function). The function will return true if the condition is met; otherwise, false will be returned. Here is the specification of the function. The function named compare Function will take three input parameters: obj1: Int? obj2: String? cond: (val1: Int, val2: Int) -> Boolean The function has Boolean as its return type. The parameter cond is a lambda function defining the condition (specified by users) used to compare two Int objects. You function needs to do the following. 1. Convert the obj2 object from String into an Int type. Please consider use the String.tolnt() method for this. Let's assume that obj2 only contain numeric characters so the String.tolnt() always works. 2. If the input object (obj1 or obj2) is null, initialize it as 0 before passing to the lambda function. Please only use the operators ?., ?:, and !! to accomplish this. 3. Invoke the lambda function with the objects obtained from step 1 and 2. 4. Return the value obtained from step 3. To test your function, use the code snippet like below. val result = compareFunction(null, "4") {x, y -> x >= y} In addition to testing the scenarios where obj1 or obj2 might be null, you also need to test all possible conditions to compare two Int objects such as 1. The first Int is greater than the second one 2. The first Int is less than the second one 3. The first one equals to the second one [Optional Type and Higher Order Function] You will implement a higher order function to compare two objects (of Int and String type) by applying a user-defined condition (via a lambda function). The function will return true if the condition is met; otherwise, false will be returned. Here is the specification of the function. The function named compare Function will take three input parameters: obj1: Int? obj2: String? cond: (val1: Int, val2: Int) -> Boolean The function has Boolean as its return type. The parameter cond is a lambda function defining the condition (specified by users) used to compare two Int objects. You function needs to do the following. 1. Convert the obj2 object from String into an Int type. Please consider use the String.tolnt() method for this. Let's assume that obj2 only contain numeric characters so the String.tolnt() always works. 2. If the input object (obj1 or obj2) is null, initialize it as 0 before passing to the lambda function. Please only use the operators ?., ?:, and !! to accomplish this. 3. Invoke the lambda function with the objects obtained from step 1 and 2. 4. Return the value obtained from step 3. To test your function, use the code snippet like below. val result = compareFunction(null, "4") {x, y -> x >= y} In addition to testing the scenarios where obj1 or obj2 might be null, you also need to test all possible conditions to compare two Int objects such as 1. The first Int is greater than the second one 2. The first Int is less than the second one 3. The first one equals to the second one

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!