THINK FIRST·CODE LATER

← All labs

Fix and clean the AI's late-penalty code

Problem

The syllabus rule for late submissions in StudyBuddy's "deadline" feature is:

  • submitted on time (0 days late or earlier) → full score;
  • 1 to 7 days late → lose 10% of the score per day late;
  • more than 7 days late → 0;
  • the result is rounded to the nearest integer (halves up), and never negative.

An AI assistant produced this method:

static int f(int s, int d) {
    int r = s;
    if (d > 0) r = s - s / 10 * d;     // 10% per day
    if (d >= 7) r = 0;
    return r;
}

It has two bugs (look closely at integer division and at the boundary) and several smells. Write a clean, correct program.

Input: lines score daysLate until the end of input (score 0–100 integer, daysLate any integer). For each, print score=S late=D -> R. At the end print Checked n submissions.

Input:

85 0
85 1
85 7
85 8
100 3
67 2

Output:

score=85 late=0 -> 85
score=85 late=1 -> 77
score=85 late=7 -> 26
score=85 late=8 -> 0
score=100 late=3 -> 70
score=67 late=2 -> 54
Checked 6 submissions

(For 85 and 1 day: 85 × 0.9 = 76.5 → 77. The AI version gives 77 only by luck: 85 / 10 * 1 = 8.)

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.