Today you'll read, test and extend a complete program that uses this week's ideas: a command-driven task tracker that saves to JSON, reports on overdue work and is checked without using a real clock or disk.
The commands
The tracker reads one command per line.
| Command | Effect |
|---|---|
add <priority> <yyyy-MM-dd> <title> | Adds a task. Priority is Low, Normal or High |
done <id> | Marks a task done. Repeating this changes nothing |
remove <id> | Removes a task. Its id isn't used again in that session; after a save and load, the highest id can come back |
list | Open tasks first, then by due date, priority and id |
report | Counts of open, done and overdue tasks, then open tasks by priority |
save <file> | Writes JSON, through a temporary file |
load <file> | Replaces the tasks, only if the file is present and valid |
today <yyyy-MM-dd> | Fixes the date that report uses, for repeatable runs |
The rules
- Titles hold 1 to 60 characters after trimming.
- A task due today isn't overdue, and a finished task is never overdue.
- A bad command prints an
Error:line, and later lines still run. - After a load, new ids continue from the highest loaded id.
Where does each rule live?
Each part has one job, and each job uses a lesson from this week.
| File | Job | Comes from |
|---|---|---|
Models.cs | The data: TaskItem, Priority, Result | Days 1, 2 and 4 |
Tracker.cs | Rules that change tasks | Day 4 results |
Reports.cs | Sorted lists and totals, with no changes | Day 3 LINQ |
Stores.cs | ITaskStore and its JSON implementation | Days 1 and 5 |
Clock.cs | IClock and its two implementations | Day 6 |
Commands.cs | Turns text into calls, and results into text | Day 4 patterns |
Program.cs | Reads the console and wires it all up | Day 6 |
Only Program.cs touches the console, so everything else can be tested from a check.
Trace it by hand
This small version of the report's rule is worth predicting exactly, because its edge cases are in the brief. Why is each line what it is?
var today = new DateOnly(2026, 11, 2);
var tasks = new[]
{
new TaskItem(1, new DateOnly(2026, 11, 1), false),
new TaskItem(2, new DateOnly(2026, 11, 2), false),
new TaskItem(3, new DateOnly(2026, 11, 1), true),
new TaskItem(4, new DateOnly(2026, 11, 3), false),
};
foreach (TaskItem task in tasks.Where(task => !task.Done && task.Due < today))
{
Console.WriteLine(task.Id);
}
Console.WriteLine($"Open: {tasks.Count(task => !task.Done)}");
record TaskItem(int Id, DateOnly Due, bool Done);Check your prediction
1
Open: 3Task 2 is due today, so it isn't late yet. Task 3 is late but done. Task 4 is in the future.
Now the list order. Each sort key only matters when those before it tie, so reading the chain from top to bottom gives the rule.
var tasks = new[]
{
new Row(1, "Low", 0, new DateOnly(2026, 11, 5), false),
new Row(2, "High", 2, new DateOnly(2026, 11, 5), false),
new Row(3, "Low", 0, new DateOnly(2026, 11, 1), true),
new Row(4, "Low", 0, new DateOnly(2026, 11, 9), false),
};
var ordered = tasks
.OrderBy(task => task.Done)
.ThenBy(task => task.Due)
.ThenByDescending(task => task.Rank)
.ThenBy(task => task.Id);
Console.WriteLine(string.Join(",", ordered.Select(task => task.Id)));
record Row(int Id, string Priority, int Rank, DateOnly Due, bool Done);Check your prediction
2,1,4,3false sorts before true, which puts open tasks first. Task 3 is done, so it comes last even though it has the earliest date.
Your turn
State the priority rule
The report command prints High, Normal and Low even when a count is 0. Enum.GetValues<Priority>() returns them in declared order, Low first. Write a program with enum Priority { Low, Normal, High } and a dictionary of counts holding only High = 2. Print every priority, highest first, in the form High: 2, using 0 when a count is missing.
When it works, it prints:
High: 2
Normal: 0
Low: 0var counts = new Dictionary<Priority, int> { [Priority.High] = 2 };
Console.WriteLine(counts.Count);
enum Priority { Low, Normal, High }Hint 1: the idea
Loop over the enum's values, not over the dictionary, because the dictionary lacks the missing ones.
Hint 2: a first step
Print Enum.GetValues<Priority>() in a loop first. LINQ's Reverse flips the order, and GetValueOrDefault deals with the missing counts.
Show one solution
var counts = new Dictionary<Priority, int> { [Priority.High] = 2 };
foreach (Priority priority in Enum.GetValues<Priority>().Reverse())
{
Console.WriteLine($"{priority}: {counts.GetValueOrDefault(priority)}");
}
enum Priority { Low, Normal, High }High: 2
Normal: 0
Low: 0Enum.GetValues<Priority>() lists the values in declaration order, Low first, so Reverse() gives the report's High-to-Low order without a hand-written list that could fall out of step with the enum. GetValueOrDefault prints 0 for a priority with no tasks, so every priority always gets a line.
Completion is saved in this browser only. It does not measure mastery.