Question: 1) In Java you will be using the java.awt.Point class. Create a public static method named getDistance that takes as input 2 Point objects. The

1) In Java you will be using the java.awt.Point class. Create a public static method named getDistance that takes as input 2 Point objects. The distance between 2 points is calculated as (21)2+(21)2. Calculate the distance between the 2 points and return the result as a double.

2) Create a public static method named updatePoint that takes as input a Point and two integers, x and y. Update the x and y coordinates of the point object to the parameters x and y. Return the Point object. Note: Do not create a new Point object.

Code so far:

import java.awt.Point;

public class Main { public static void printPoint(Point p) { System.out.println("(" + p.x + ", " + p.y + ")"); } public static double getDistance(Point p1, Point p2) { //method for calculating distance double dx = p2.x - p1.x; // calling points for x (3 - 0) double dy = p2.y - p1.y; // calling points for y (4 - 0) return Math.sqrt((dx * dx) + (dy *dy)); //equation for distance } public static void updatePoint(Point p) { return new Point(5, 5); } public static void main(String[] args) { Point p1 = new Point(0, 0); //point 1 at (0,0) Point p2 = new Point(3, 4); //point 2 at (3,4) Point answer = updatePoint(p1, 2, 2); // Not sure what to do here double dist = p1.distance(p2); // ???? } }

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!