package com.operators;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.function.BinaryOperator;
public class TotalCost {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double mealCost = scan.nextDouble(); // original meal price
int tipPercent = scan.nextInt(); // tip percentage
int taxPercent = scan.nextInt(); // tax percentage
scan.close();
Map<Double,Double> map = new HashMap<>();
map.put(mealCost, (double)tipPercent);
map.put(mealCost, (double)taxPercent);
BinaryOperator<Double> opPercent = (t1,t2) -> (t1*t2)/100;
BinaryOperator<Double> opSum = (t1,t2) -> (t1+t2);
calculation(opPercent,map);
}
public static void calculation(BinaryOperator<Double> opPercent , Map<Double,Double> map) {
List<Double> biList = new ArrayList<>();
map.forEach((s1,s2)-> biList.add(opPercent.apply(s1, s2)));
}
}
- I have the below problem which I am trying to solve in Java 8 using BinaryOperator.There are three inputs to this application [mealCost(double), tipPercent(int),taxPercent(int)].
I am trying to calculate the below values :
tip = (mealCost*tipPercent)/100; tax = (mealCost*taxPercent)/100; TotalCost = mealCost+tip +tax;I am unable to pass an integer input to the apply method of BinaryOperator. Also the calculated value into biList is not proper. Below is my code