This checkpoint combines Day 1's named values with today's decisions and loops. Begin with a trace, not with code. List the days, the amount on each day and the running total. Then decide where initialization, updates and final reporting belong. You should not need methods or arrays yet.
The brief
A learner studies for 10, 20, 30 and 40 minutes on four consecutive days. Count days with at least 25 minutes, total all four days and report whether the total reaches a 90-minute goal. Use a loop to derive the amounts from day * 10. Do not write four separate additions or hard-code the final boolean answer.
Two smaller patterns
The worked examples use a different measurement. Explain what transfers and what does not: the accumulator pattern transfers, but the checkpoint's rule about long days is a separate decision you must add yourself.
public class Main {
public static void main(String[] args) {
int distance = 0;
for (int trip = 1; trip <= 3; trip++) {
distance += trip * 2;
}
System.out.println(distance);
System.out.println(distance >= 12);
}
}Check your prediction
12
trueThe distance is 2+4+6. Comparison belongs after the accumulation when the question is about the whole plan. A comparison inside the loop asks about each partial total instead.
public class Main {
public static void main(String[] args) {
int matches = 0;
for (int value = 1; value <= 4; value++) {
if (value >= 3) {
matches++;
}
}
System.out.println(matches);
}
}Check your prediction
2Counting does not require storing the selected values. In the checkpoint, compare the derived minute amount rather than comparing the day number directly to 25.
Plan your acceptance cases
Predict each row on paper before you write the loop. Each one is a run with
different days or goal values.
| Case | Expected behavior | Skill it checks |
|---|---|---|
| Four days, goal 90 | Total 100, long-day count 2, goal true | The main report |
| Two days, 10 and 20 minutes | Total 30, long-day count 0, goal false | Total all days, count only qualifying days |
| Four days and a goal of exactly 100 | Total 100, long-day count 2, goal true | Inclusive goal comparison |
| Zero days | Total 0, long-day count 0, goal false | Empty traversal |
When your version works, break it on purpose: change >= goal to > goal.
Which row now gives the wrong answer? Put it back.
Your turn
Build the weekly report
Implement the four-day study plan. Print Total: 100, Long days: 2 and Goal reached: true. Keep day count and goal as starting variables so the acceptance cases can be checked by changing inputs.
public class Main {
public static void main(String[] args) {
int days = 4;
int goal = 90;
// Build and report the weekly totals.
}
}Hint 1: the idea
The total changes every day, but the long-day count changes only when its separate condition matches.
Hint 2: a first step
Initialize both accumulators before the loop. Inside it, derive the current duration before using it in either calculation.
Show one solution
public class Main {
public static void main(String[] args) {
int days = 4;
int goal = 90;
int total = 0;
int longDays = 0;
for (int day = 1; day <= days; day++) {
int minutes = day * 10;
total += minutes;
if (minutes >= 25) {
longDays++;
}
}
System.out.println("Total: " + total);
System.out.println("Long days: " + longDays);
System.out.println("Goal reached: " + (total >= goal));
}
}Total: 100
Long days: 2
Goal reached: trueEvery day adds to total, but only the if (minutes >= 25) branch adds to
longDays. The goal is compared once, after the loop, because the question is
about the whole week; >= makes a goal of exactly 100 count as reached.
Change it and explain
Make a three-column trace: day, total and longDays. Find the first row where a mistaken implementation differs from yours. This is often faster than staring at the final number and guessing at a fix.
Close the solution and write the equivalent report for three reading sessions of 5, 10 and 15 pages, counting sessions of at least 10 pages. Explain the connection between the tasks without reusing the old answers. If you can transfer the pattern, you are ready to package useful operations as methods tomorrow.
Completion is saved in this browser only. It does not measure mastery.