Exercise: Logistics Tracking

Implement a basic interface to track the location of shipping containers.

Problem statement

A shipping company requires a standardized method to track cargo across its supply chain. Define a contract for trackable items and implement it for a freight container.

Task requirements

  • Define an ITrackable interface with a TrackingId string property and an UpdateLocation method.

  • Create a FreightContainer class that implements the ITrackable interface.

  • Ensure your implementation works with the provided Program.cs execution logic.

Constraints

  • You must place all types in the Logistics file-scoped namespace.

  • FreightContainer must initialize the TrackingId property to string.Empty to satisfy null-safety requirements.

  • The UpdateLocation method must print exactly "Container {TrackingId} is now at: {newLocation}".

Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.

Get hints

  • Use the interface keyword to define ITrackable.

  • Interface members do not have access modifiers like public, as they are public by default.

  • Use the colon : syntax in the class definition to implement the interface.

Exercise: Logistics Tracking

Implement a basic interface to track the location of shipping containers.

Problem statement

A shipping company requires a standardized method to track cargo across its supply chain. Define a contract for trackable items and implement it for a freight container.

Task requirements

  • Define an ITrackable interface with a TrackingId string property and an UpdateLocation method.

  • Create a FreightContainer class that implements the ITrackable interface.

  • Ensure your implementation works with the provided Program.cs execution logic.

Constraints

  • You must place all types in the Logistics file-scoped namespace.

  • FreightContainer must initialize the TrackingId property to string.Empty to satisfy null-safety requirements.

  • The UpdateLocation method must print exactly "Container {TrackingId} is now at: {newLocation}".

Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.

Get hints

  • Use the interface keyword to define ITrackable.

  • Interface members do not have access modifiers like public, as they are public by default.

  • Use the colon : syntax in the class definition to implement the interface.

C# 14.0
using Logistics;
ITrackable container = new FreightContainer();
container.TrackingId = "CONT-12345";
container.UpdateLocation("Port of Los Angeles");