logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

Write a Java class Point to represent a point with x and y coordinates. The

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

I just need the first question

 

Question 3 (5 points):

Q3) Write a Java class Point to represent a point with x and y coordinates. The

class Point has the following:

Attributes:

• double x

• double y

Methods:

• Setters and getters for x and y.

• distance(Point p): double. This method returns the distance between the two

points: p and the calling object.

hint: to compute distance between two points, use the equation:

Distance = √(𝑥2 − 𝑥1)

2 + (𝑦2 − 𝑦1)

2

Write another class TestPoint that does the following:

1. Declare two Point objects p1 and p2

2. Read the values of x and y for both points.

3. Compute the distance between the two points using the method distance,

if the distance is less than or equal to 5.0 you should print the distance and

exit. Otherwise keep reading two more points and printing the distance

until you get two points with distance less than or equal to 5.0.

Sample run1:

Enter x and y for p1 1 2

Enter x and y for p2 6 8

Distance is 7.810249675906654 which is > 5. Try again.

Enter x and y for p1 2 6

Enter x and y for p2 9 18

Distance is 13.892443989449804 which is > 5. Try again.

Enter x and y for p1 1 1

Enter x and y for p2 4 3

The two points are close.

The distance between them is 3.605551275463989 which is

less than 5

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

991 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

681 Answers

Hire Me
expert
Husnain SaeedComputer science

583 Answers

Hire Me
expert
Atharva PatilComputer science

838 Answers

Hire Me

Get Free Quote!

367 Experts Online