Double equality on summed floats
Review this Java method that sums an order's line totals (each a dollar amount) and compares to the charged amount before settling.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 18 min
Mark a line and say what kind of problem it is.0 findings
1boolean reconciles(List<Double> lineTotals, double charged) {
2 double sum = 0.0;
3 for (double t : lineTotals) {
4 sum += t; // dollars, e.g. [0.10, 0.20]
5 }
6 if (sum == charged) { // charged also a dollar double, e.g. 0.30
7 log.info("order reconciled: {}", sum);
8 return true;
9 }
10 log.warn("mismatch: sum={} charged={}", sum, charged);
11 return false;
12}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.