Commit f420227

mokha <mokha@cisco.com>
2019-04-28 22:29:28
complete cartesian coordinate
1 parent 5d157c2
Changed files (3)
assignments
assignment1
src
main
java
ca
test
java
assignments/assignment1/src/main/java/ca/mokhan/assignment1/CartesianCoordinateSystem.java
@@ -0,0 +1,11 @@
+package ca.mokhan.assignment1;
+
+import java.util.Objects;
+
+public class CartesianCoordinateSystem
+{
+  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;
+  }
+}
assignments/assignment1/src/test/java/ca/mokhan/assignment1/CartesianCoordinateSystemTest.java
@@ -0,0 +1,26 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class CartesianCoordinateSystemTest extends TestCase
+{
+  private CartesianCoordinateSystem subject;
+
+  public CartesianCoordinateSystemTest(String testName)
+  {
+    super(testName);
+    this.subject = new CartesianCoordinateSystem();
+  }
+
+  public static Test suite()
+  {
+    return new TestSuite(CartesianCoordinateSystemTest.class);
+  }
+
+  public void testDistanceBetweenPoints()
+  {
+    assertEquals(7.28, subject.calculateDistance(-2, -3, -4, 4));
+  }
+}
assignments/assignment1/README.md
@@ -77,7 +77,15 @@ Write a program to compute the total bonus amount earned by these two employees
 
 ```ruby
 class BonusOnSavings
-  def computeBonus(commitment, q1, q2, q3, q4)
+  def compute_bonus(commitment, q1, q2, q3, q4)
   end
 end
 ```
+
+3. Write a program that prompts the user to enter two points `(x1, y1)` and `(x2, y2)`.
+Calculate and display the distance between the two points using the formula below.
+Round the answer up to 2 decimal points.
+You can use `Math.pow(a,0.5)` to compute the square root of an expression.
+`Math.pow()` returns a double.
+
+For example, the distance between the points (โˆ’2, โˆ’3) and (โˆ’4, 4) is approximately 7.28, as shown below.