A Century of Missing Interest — Java Bug Hunt

Inspired by the interest-calculation bugs that have triggered real banking remediations: integer division runs before multiplication, rate / 100 becomes…

  • Language: Java
  • Layer: Backend
  • Difficulty: Medium
  • Concepts: Integer Division, Finance
  • Modelled on: Core banking
  • Visible tests: one year of five percent; two years compound; zero years returns the principal
  • Reward: 50 XP for a complete fix

Briefing

Inspired by the interest-calculation bugs that have triggered real banking remediations: integer division runs before multiplication, rate / 100 becomes zero, and a decade of compounding earns exactly nothing.

Interest.java compounds yearly, in integer cents.

Bug report

BUG-DIV0INT · Priority: Critical (regulatory) · Reported by: core banking

compound(principalCents, ratePercent, years):

  • one compounding per year: value = value * (100 + rate) / 100 (floor)
  • 10000 cents at 5% for 1 year -> 10500; 2 years -> 11025

Observed: every account earned 0 interest — 5 / 100 is 0 in integer math.

Logs

[interest] 10000 @ 5% x 10y -> 10000

The code as shipped

Interest.java (editable)

class Interest {
    static long compound(long principalCents, int ratePercent, int years) {
        long value = principalCents;
        for (int i = 0; i < years; i++) {
            value = value + value * (ratePercent / 100);
        }
        return value;
    }
}

Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More Java bug hunts.