I have a kind of calculator:
sum = value1 + value2;
multiplication = value1 * value2;
division = (value1 / value2);
average = (sum / 2);
if (operation.compareToIgnoreCase("add") == 0)
result = sum;
else if (operation.compareToIgnoreCase("mult") == 0)
result = multiplication;
else if (operation.compareToIgnoreCase("div") == 0)
result = division;
else if (operation.compareToIgnoreCase("avg") == 0)
result = average;
And i have to turn this to lambda expressions:
result = (request.getValue1(), request.getValue2()) -> {
if (request.getOperation().compareToIgnoreCase("add") == 0) return request.getValue1() + request.getValue2();
else if (request.getOperation().compareToIgnoreCase("mult") == 0) return request.getValue1() * request.getValue2();
else if (request.getOperation().compareToIgnoreCase("div") == 0) return request.getValue1() / request.getValue2();
else if (request.getOperation().compareToIgnoreCase("avg") == 0) return (request.getValue1() + request.getValue2())/2;
}
But it doesnt work. Can you guys help? Thanks
Map<String,something>instead of thoseifstatements.