HomeChallengesRepsProblemsLeaderboardTake a challenge

Two callers, one copy of the data

Lagos and Nairobi share one static calendar module. Each configures it and then asks a question, and because the calls interleave, Lagos gets Nairobi’s answers. Give each school its own copy of the data.

Beginner10 min on the clock5 graded checks · 100 pointsFrom Procedures to Objects
Graded by reading your code against the checklist below.

What you build

  • Turn the static class into a class with instance fields
  • Give it a constructor that takes the intake month, day and minimum age
  • Create one object per school in Main
  • Delete Configure
  • Work out both schools’ answers for 20181231 and fill in Answers.cs

Done means

No static data, one object per school built by a constructor, no Configure, and both answers traced correctly.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else.

  1. No static fields remain+25Data that belongs to one object
  2. A constructor sets the three settings+20Data that belongs to one object
  3. Each school gets its own object+15Data that belongs to one object
  4. Both answers traced correctly+30Data that belongs to one object
  5. Configure is gone+10Data that belongs to one object

What it teaches

Data that belongs to one objectbeginner

A static field exists once for everyone, so two callers overwrite each other; an object is a private copy of the data, and its methods reach that copy through the this the compiler passes for you.

The rest of From Procedures to Objects