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)));
}
}
- 我有我試圖在Java中8解決使用BinaryOperator.There被三個輸入到本申請[mealCost(雙),tipPercent(INT)的以下問題,taxPercent (INT)。
我試圖計算出以下值:加成在Java中使用8 BinaryOperator
tip = (mealCost*tipPercent)/100; tax = (mealCost*taxPercent)/100; TotalCost = mealCost+tip +tax;
我無法整數輸入傳遞到BinaryOperator的應用方法。此外,計算的值biList是不適當的。 以下是我的代碼
您可能還需要使用'DoubleBinaryOperator'其使用,而不是'Double'包裝的原始值 – Lino