Challenge 4: Calculate Distance Between Points
Explore how to implement a Java class that represents points in 2D space. Learn to create constructors to initialize these points and develop methods to calculate distances both from the origin and between points. This lesson helps you understand applying classes and methods to solve geometric problems using object-oriented programming in Java.
We'll cover the following...
Problem Statement
You have to implement a class called Point that represents a specific point in the x-y plane. It should contain the following:
-
fields:
-
x( integer type) -
y( integer type)
-
-
methods:
-
default constructor that initializes the point at
-
parameterized constructor that takes input
xandyand initializes the point to the respective coordinates. -
float distance(), a method which calculates the distance of the point (represented by the object) from the origin, i.e. ...
-