Exercise: Logistics Tracking
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
ITrackableinterface with aTrackingIdstring property and anUpdateLocationmethod.Create a
FreightContainerclass that implements theITrackableinterface.Ensure your implementation works with the provided
Program.csexecution logic.
Constraints
You must place all types in the
Logisticsfile-scoped namespace.FreightContainermust initialize theTrackingIdproperty tostring.Emptyto satisfy null-safety requirements.The
UpdateLocationmethod 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
interfacekeyword to defineITrackable.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
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
ITrackableinterface with aTrackingIdstring property and anUpdateLocationmethod.Create a
FreightContainerclass that implements theITrackableinterface.Ensure your implementation works with the provided
Program.csexecution logic.
Constraints
You must place all types in the
Logisticsfile-scoped namespace.FreightContainermust initialize theTrackingIdproperty tostring.Emptyto satisfy null-safety requirements.The
UpdateLocationmethod 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
interfacekeyword to defineITrackable.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.