Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
Error al escribir el método de reducción usando Stream API
@Getter public class Dish { BigDecimal price; }

Necesito calcular el precio total de todos los platos pedidos , pero no puedo escribir el método de reducción. Esta es una firma de método (el argumento tiene un mapa de Dish y cuántas veces se ordenó).

Así que debe ser algo así como la sum of every dish.getPrice * dishQuantaty

 private BigDecimal getOrderTotalPrice(Map<Dish, Integer> dishQuantityMap) { }

El código de error sobre el que me preguntaron

 return dishQuantityMap.entrySet().stream() .reduce(BigDecimal.ZERO, (dishIntegerEntry) -> dishIntegerEntry.getKey().getPrice() .multiply(BigDecimal.valueOf(dishIntegerEntry.getValue())));
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

¿Quiso decir algo como esto?

 private BigDecimal getOrderTotalPrice(Map<Dish, Integer> dishQuantityMap) { return dishQuantityMap.entrySet().stream() .map(d -> d.getKey().getPrice().multiply(new BigDecimal(d.getValue()))) .reduce(BigDecimal.ZERO, BigDecimal::add); }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!