Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Make a code for a class named Point to represent a point in the Cartesian plane with x and y coordinates. This class contains:

Python

Make a code for a class named Point to represent a point in the Cartesian plane with x and y coordinates. This class contains:

Two instance variables x and y that represent the coordinates with getX() and getY() methods.

A constructor that constructs a point with specified coordinates, with default values 0 and 0.

An __str__ method to return a string representation in the form (x, y).

A method named distance that returns the distance from this point to another point. The formula for finding the distance between the two points (x1,y1) and p2(x2, y2) is math.sqrt((x2- x1)2 + (y2-y1)2)

A method named originDistance that returns the distance from this point to the point of origin (0,0).

Appropriate code so that points can be compared using the comparison operators. Points are compared based on their distance from the origin.

Add a test program that does the following:

Creates a point object, named p0, that uses the default values for the coordinates.

Print p0

Creates a point object, named p1, with coordinates at (3,4)

Print p1

Creates a point object, named p2, with coordinates at (3,0). When creating the object, take advantage of the fact that the value of the y-ccordinate is the default value of the corresponding parameter.

Print the x and y coordinates of p2 using the getX() and getY() methods

Find and print the distance between p1 and p2

Print the results of comparing p1 and p2. Make sure to test all 6 comparison operators.

Your code should allow using == and != to compare a Point object with an object of a different type. Print the result of using the equality and inequality operators to compare p1 with the string "Hello".

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

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

=+What is the most that you should pay to complete development?

Answered: 1 week ago

Question

What should the FASB-conceptual-framework look into next?

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago