summaryrefslogtreecommitdiff
path: root/src/Q3/CartesianCoordinateSystem.java
blob: c41dbeb9e9fce8a875ee4b29cd4e58130886767d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
 * Assignment 1, COMP268 Class: CartesianCoordinateSystem.java
 *
 * @description Represents an object that can calculate the distance between two points on a
 *     cartesian plain
 * @author: mo khan Student ID: 3431709
 * @date May 7, 2019
 * @version 1.0
 */
package Q3;

public class CartesianCoordinateSystem {
  /**
   * Calculate the distance between two points.
   *
   * @param x1 x coordinate for the first point.
   * @param y1 y coordinate for the first point.
   * @param x2 x coordinate for the second point.
   * @param y2 y coordinate for the second point.
   * @return the distance between the two points
   */
  public double calculateDistance(double x1, double y1, double x2, double y2) {
    return Math.round(Math.pow(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2), 0.5) * 100) / 100.0;
  }
}