Question: package edu.wit.cs.comp1050; //TODO: document this class public class Point2D { /** * Constructor to initialize coordinates * * @param x x value * @param y

 package edu.wit.cs.comp1050; //TODO: document this class public class Point2D { /**

package edu.wit.cs.comp1050; //TODO: document this class public class Point2D { /** * Constructor to initialize coordinates * * @param x x value * @param y y value */ public Point2D(double x, double y) { // replace with your code } /** * Initializes to (0., 0.) */ public Point2D() { // replace with your code // MUST be a single call // to the constructor above } /** * Get the x coordinate * * @return x coordinate */ public double getX() { return 0.; // replace with your code } /** * Get the y coordinate * * @return y coordinate */ public double getY() { return 0.; // replace with your code } /** * Gets a String representation * of the coordinate in the form * "(x, y)" (each with three decimal * places of precision) * * #return "(x, y)" */ public String toString() { return ""; // replace with your code } /** * Method to compute the Euclidean/L2 * distance between two points in 2D * space * * @param p1 point 1 * @param p2 point 2 * @return straightline distance between p1 and p2 */ public static double distance(Point2D p1, Point2D p2) { return 0.; // replace with your code } /** * Method to compute the Euclidean * distance between this point * and a supplied point * * @param p input point * @return straightline distance between this point and p */ public double distanceTo(Point2D p) { return 0.; // MUST be a single call to the static distance method } }
package edu.wit.cs.comp1050; //TODO: document this class public class PA3c { /** * Error to display if the command-line arguments are invalid */ public static final String ERR_USAGE = "Please supply 2 numbers (x y)."; /** * Computes the distance using three methods * from the origin to a point supplied via * command-line arguments * * @param args command-line args: x y */ public static void main(String[] args) { // replace the following line // with whatever code you see fit // in order to validate command-line // arguments and, if valid, construct // p via the two doubles supplied final Point2D p = new Point2D(); ////////////////////////////////////// // !! DO NOT CHANGE THE LINES BELOW !! // // They assume p has been // properly constructed and perform // all necessary output for the // program ////////////////////////////////////// final Point2D o = new Point2D(); System.out.printf("Point 1: %s%n", o); System.out.printf("Point 2: %s%n", p); System.out.printf("Static method distance: %.3f%n", Point2D.distance(o, p)); System.out.printf("Distance from P1: %.3f%n", o.distanceTo(p)); System.out.printf("Distance from P2: %.3f%n", p.distanceTo(o)); } }

Problem c (PA . Java) You are first to implement a class named Point2D to store a coordinate pair (x,y) and to compute Euclidean/L2 distances 1 between points in two-dimensional space. The class has one constructor to initialize the coordinates and a no-arg constructor (which you should make use the first) that sets the point to the origin (0,0). It has getter methods for both coordinates, as well as a tostring method to return the familiar (x,y) format (both with three decimal places of precision). Finally there's a static method to calculate the Euclidean distance between two points, and a member method (which must use the static method) to calculate from one instance to a supplied other. You must also complete a program that takes a single point via command-line arguments and computes the distance from the origin. Much of the main method has been written for you - you must validate commandline arguments and then construct a Point2D instance according to the supplied values. The following represent example runs... $ java edu.wit.cs.comp1050.PA3c Please supply 2 numbers (x y). $ java edu.wit.cs.comp1050.PA3c 01 Point 1: (0.000,0.000) Point 2: (0.000, 1.000) Static method distance: 1.000 Distance from P1: 1.000 Distance from P2: 1.000 $ java edu.wit.cs.comp1050.PA3c 1030.5 Point 1: (0.000, 0.000) Point 2: (10.000, 30.500) Static method distance: 32.098 Distance from P1: 32.098 Distance from P2: 32.098

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!