Challenge: Refactor a Coordinate Struct
Task
Swipe to start coding
Refactor the provided Coordinate struct into a class and add a method to calculate the distance to another Coordinate object.
- Replace the struct with a class named
Coordinatethat hasXandYproperties. - Implement a constructor that accepts values for
XandY. - Add a method named
DistanceTothat takes anotherCoordinateobject as a parameter and returns the Euclidean distance between the two coordinates. - The distance is calculated as the square root of the sum of the squared differences of the
XandYvalues.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 4. ChapterΒ 4
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Suggested prompts:
Can you explain this in simpler terms?
What are the main points I should remember?
Can you give me an example?
Awesome!
Completion rate improved to 4.17
Challenge: Refactor a Coordinate Struct
Swipe to show menu
Task
Swipe to start coding
Refactor the provided Coordinate struct into a class and add a method to calculate the distance to another Coordinate object.
- Replace the struct with a class named
Coordinatethat hasXandYproperties. - Implement a constructor that accepts values for
XandY. - Add a method named
DistanceTothat takes anotherCoordinateobject as a parameter and returns the Euclidean distance between the two coordinates. - The distance is calculated as the square root of the sum of the squared differences of the
XandYvalues.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 4. ChapterΒ 4
single