static double fax(int salary) {
Map<Integer,Function<Integer,Double>> amap =new LinkedHashMap<>();
amap.put(5000,i->0d);
amap.put(8000,i->0.03*(i-5000));
amap.put(17000,i->0.07*(i-8000));
amap.put(30000,i->0.10*(i-17000));
amap.put(40000,i->0.05*(i-30000));
amap.put(60000,i->0.05*(i-40000));
amap.put(85000,i->0.05*(i-60000));
amap.put(Integer.MAX_VALUE,i->0.05*(i-85000));
Double sum =0d;
for (Map.Entry<Integer, Function<Integer, Double>> integerFunctionEntry : amap.entrySet()) {
sum +=integerFunctionEntry.getValue().apply(salary);
if(salary<=integerFunctionEntry.getKey()) break;
}
return sum;
}
public static void main(String[] args) {
int[] yourSalarys={3500,5000,7500,8000,17000,18000,30000,31000,60000};
Arrays.stream(yourSalarys).forEach(o->{
double fax = fax(o);
System.out.println("Salary before fax----->" + o );
System.out.println("fax------------------->" + fax );
System.out.println("Salary after fax------>" + (o-fax));
System.out.println("--------------------------");
});
}