QuestionQuestion

Design a class named Point to represent a point with x- and y-coordinates. The class contains:
- Two private data fields x and y that represent the coordinates with getter methods.
- A constructor that constructs a point with specified coordinates, with default(0, 0).
- A method named distance that returns the distance from this point to another point of the Point type.
- A method named isNearBy(p1) that returns True if point p1 is close to this point. Two points are close if their distance is less than 5.
- Implement the __str__ method to return a string in the form (x, y).
Draw the UML diagram for the class, and then implement the class. Write a test program that prompts the user to enter two points, displays the distance between them, and indicates whether they are near each other.
Sample Run 1
Enter the x-coordinate of point1: 2.1
Enter the y-coordinate of point1: 2.3
Enter the x-coordinate of point2: 19.1
Enter the y-coordinate of point2: 19.2
The distance between the two points is 23.97
The two points are not near to other
Sample Run 2
Enter the x-coordinate of point1: 2.1
Enter the y-coordinate of point1: 2.3
Enter the x-coordinate of point2: 2.3
Enter the y-coordinate of point2: 4.2
The distance between the two points is 1.91
The two points are near to other

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import math
from builtins import print


class Point:
    def __init__(self, x=0, y=0):
       """
       A constructor that constructs a point with specified coordinates, with default(0, 0)
       Two private data fields x and y that represent the coordinates with getter methods.
       :param x:
       :param y:
       """
       self.x = x
       self.y = y
       pass

    def get_x(self) -> float:
       return self.x

    def get_y(self) -> float:
       return self.y

    def distance(self, point) -> float:
       """
         A method named distance that returns the distance from this point to another point of the Point type.
       :param point:
       """
       dx = float(self.x) - float(point.get_x())
       dy = float(self.y) - float(point.get_y...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$11.70
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats