Calculates the distance between two points of N dimensional space.
If the two points are in different dimensions, print the distance as -1.
Use Euclid Distance and Manhattan Distance.
Thanks!
**Use the code below and complete the rest.**
public class Distance2 {
public static void main(String[] args) {
Point p1 = new Point(new double[] {1.0, 2.0, 3.0});
Point p2 = new Point(new double[] {4.0, 5.0, 6.0});
System.out.println("Euclidean Distance: " +
EuclidDistance.getDist(p1, p2));
System.out.println("Manhattan Distance: " +
ManhattanDistance.getDist(p1, p2));
Point p3 = new Point(new double[] {1.0, 2.0, 3.0});
Point p4 = new Point(new double[] {4.0, 5.0});
System.out.println("Euclidean Distance: " +
EuclidDistance.getDist(p3, p4));
System.out.println("Manhattan Distance: " +
ManhattanDistance.getDist(p3, p4));
}
}
Create a new class Point.java and copy the following code
class Point
{
private double []coords;
Point ( double[] coords)
{
this.coords = coords;
}
double[] getCoords()
{
return this.coords;
}
}
Create a new class EuclidDistance.java and copy the following code
class EuclidDistance
{
static double getDist(Point pt1, Point pt2)
{
if( pt1.getCoords().length == pt2.getCoords().length)
{
double sum =0;
for (int i= 0 ;i< pt1.getCoords().length;i++)
sum = sum + Math.pow((pt2.getCoords()[i] - pt1.getCoords()[i]), 2);
return Math.pow(sum,0.5);
}
else
return -1;
}
}
Create a new class ManhattanDistance.java and copy the following code
class ManhattanDistance
{
static double getDist(Point pt1, Point pt2)
{
if( pt1.getCoords().length == pt2.getCoords().length)
{
double sum =0;
for (int i= 0 ;i< pt1.getCoords().length;i++)
sum = sum + Math.abs(pt2.getCoords()[i] - pt1.getCoords()[i]);
return sum;
}
else
return -1;
}
}
Calculates the distance between two points of N dimensional space. If the two points are in...
4. The below table shows four different processors P1, P2, P3, and P4 executing the same program with clock rates and average CPls as shown below. Answer the following showing all the steps. Processor Clock rate CP 1.0 GHz 4.0 GHz 3.0 GHz 2.0 GHz P1 3.0 P2 2.0 P3 1.5 P4 2.5 a. Which processor has the best performance in terms of execution time? (8 Points) b. If the program has 5000 instructions, what is the time spent on...
Make a subclass of Offering called Product. Make the Product constructor take a name and price. Implement the missing method. Submit just the Product class. public abstract class Offering { private String name; public Offering(String n) { name = n; } public abstract double getTotalCost(); public String toString() { return name + " costs $" + String.format("%.2f", getTotalCost()); } } public class Demo1 { public static void main(String[] args) { Offering p1 = new Product("iPhone", 999); Offering p2 = new...
Create a MyPoint class to model a point in a two-dimensional space. The MyPoint class contains: • Two data fields x and y that represent the coordinates. • A no-arg constructor that creates a point (0,0). • A constructor that constructs a point with specified coordinates. • Two get functions for data fields x and y, respectively. • Two set functions for data fields x and y, respectively. • A function named distance that returns the distance from this point...
Given two polynomials equation, write a function that adds and multiply the given two polynomials. It adds and multiply the two equations which are in standard form and return them in the sum poly which also be in standard form. Write one add method and one multiply method. public class pll { public static void main(String argc[]) { PLL ans_sum,ans_mul; PLL p1 = new PLL(4, 2); PLL p2 = new PLL(6, 5); p3 = p1.add(p2); p1 = new PLL(2, 4); p2...
Q.1 Chloroform (1) and n-heptane (2) forms a 2 phase systems for which the following plot is givern: 6.0 5.5 5.0 4.5 4.0 3.5 3.0 2.5 2.0 1.5 1.0 0.5 0.0 6.0 5.5 5.0 4.5 4.0 3.5 2.5- 2.0- 1.5 1.0 0.5 0.0 0.0 0.2 0.4 0.6 0.8 1.0 (a) Use Van Laar equation to calculate y?, y2 and P for x1-02. Given P1 at-44.51 kPa; P2 at-65.54kPa (b) Do the activity coefficients show positive or negative deviation from activity...
Q1. Consider these four points: P [,,5| , P2 = 2], P3 = [H]. Plot these three points. (a) Find the Manhattan distance between Pi and P2 (b) Find the Manhattan distance between P1 and P3. (e) Find the Manhattan distance between P2 and P3. Q2. Consider the same points in Q1 and find the Euclidean distances between the points specified in parts (a), (b), and (e). In other words, you will be doing the above question again but now...
Part 1: Implement a singly linked list -------------------------------------- (a) Your job is to implement a generic singly linked list that can hold any data type. The interface has been specified and provided to you in a header file called mylist.h. So your job is to write mylist.c that implements each function whose prototype is included in mylist.h. Specifically, you are asked to write the following functions: struct Node *addFront(struct List *list, void *data) void traverseList(struct List *list, void (*f)(void *))...
INSTRUCTIONS: I NEED TO CREATE A PointApp PROGRAM THAT USES THE FOLLOWING API DOCUMENTATION. Below the API Documentation is the code I submitted. However, the output is different for what they are asking. I am looking for someone to fix the code to print out the correct output and to add comments so I can have an idea in how the code works. PLEASE AND THANK YOU. API DOCUMENTATION: public class Point extends java.lang.Object The Point class is used to...
Add another method public static void displayObject(ArrayList list, int n) that will display then information on the nth object of list. If n is not a valid index, the method should generate and throw and exception that the main can then process. You get to decide what exception (one built into Java or a custom exception) and how you would like to “handle” the exception (terminate the program, prompt for more input, etc). Here is the program so far: import...
Java Help 2. Task: Create a client for the Point class. Be very thorough with your testing (including invalid input) and have output similar to the sample output below: ---After declaration, constructors invoked--- Using toString(): First point is (0, 0) Second point is (7, 13) Third point is (7, 15) Second point (7, 13) lines up vertically with third point (7, 15) Second point (7, 13) doesn't line up horizontally with third point (7, 15) Enter the x-coordinate for first...