Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

List the activities involved in employer-designed HRD programs

Answered: 1 week ago