Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Refactor a Coordinate Struct | Composition, Inheritance, and Refactoring
C# OOP Class Construction Drills

bookChallenge: Refactor a Coordinate Struct

Uppgift

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 Coordinate that has X and Y properties.
  • Implement a constructor that accepts values for X and Y.
  • Add a method named DistanceTo that takes another Coordinate object 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 X and Y values.

Lösning

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 4
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

close

bookChallenge: Refactor a Coordinate Struct

Svep för att visa menyn

Uppgift

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 Coordinate that has X and Y properties.
  • Implement a constructor that accepts values for X and Y.
  • Add a method named DistanceTo that takes another Coordinate object 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 X and Y values.

Lösning

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 4
single

single

some-alt