Question

Using Python 3: Create a point p1 of coordinates (0; 0) and un point p2 of...

Using Python 3:

Create a point p1 of coordinates (0; 0) and un point p2 of coordinates (1; 2). Print out the coordinates of
the two points on the same line, by calling toString on the two points. Print the
result of applying the method equals on point p1, using p2 as argument. Set the x
coordinate of p2 equal to the x coordinate of p1, using the methods setX and getX.
Set the y coordinate of p2 equal to the y coordinate of p1, using the method setY
and getY. Print again the result of applying the method equals on point p1, using
p2 as argument. Increment by 1 the x coordinate of p2, using the methods setX and
getX . Print again the result of applying the method equals on point p1, using p2
as argument.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
class Point:
    def __init__(self,x,y):
        if(not isinstance(x,int) or not isinstance(y,int)):
            raise ValueError("Invalid coordinate")
        self.x = x
        self.y = y

    def getX(self):
        return self.x

    def getY(self):
        return self.y

    def setX(self, X):
        self.x = X

    def setY(self, Y):
        self.y = Y

    def Print(self):
        print(self.x,self.y)

def main():
    try:
        q = Point(3, 4)
        q.Print()
        q.setX(5)
        q.setY(7)
        q.Print()
    except ValueError as ex:
        print(ex)

main()

\color{red}\underline{Output:}

Add a comment
Know the answer?
Add Answer to:
Using Python 3: Create a point p1 of coordinates (0; 0) and un point p2 of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Help 2. Task: Create a client for the Point class. Be very thorough with your...

    Java Help 2. Task: Create a client for the Point class. Be very thorough with your testing (including invalid input) and have output similar to the sample output below: ---After declaration, constructors invoked--- Using toString(): First point is (0, 0) Second point is (7, 13) Third point is (7, 15) Second point (7, 13) lines up vertically with third point (7, 15) Second point (7, 13) doesn't line up horizontally with third point (7, 15) Enter the x-coordinate for first...

  • In Java please! Problem You will be using the point class discussed in class to create...

    In Java please! Problem You will be using the point class discussed in class to create a Rectangle class. You also need to have a driver class that tests your rectangle. Requirements You must implement the 3 classes in the class diagram below and use the same naming and data types. Following is a description of what each method does. Point Rectangle RectangleDriver - x: int - top Left: Point + main(args: String[) - y: int - width: int +...

  • Create a MyPoint class to model a point in a two-dimensional space. The MyPoint class contains:...

    Create a MyPoint class to model a point in a two-dimensional space. The MyPoint class contains: • Two data fields x and y that represent the coordinates. • A no-arg constructor that creates a point (0,0). • A constructor that constructs a point with specified coordinates. • Two get functions for data fields x and y, respectively. • Two set functions for data fields x and y, respectively. • A function named distance that returns the distance from this point...

  • Implement the Point class (code for this up to the isHigher method was discussed in the...

    Implement the Point class (code for this up to the isHigher method was discussed in the lecture). The class has the following instance variables: • x coordinate (an int) • y coordinate (an int) and the following methods: • Constructor that sets the x and y coordinates • Get and set methods • Method equals if this point is equal to another point object (if the x and y coordinates are the same). • Method isHigher if this point is...

  • Must be in Java. Show proper reasoning with step by step process. Comment on the code...

    Must be in Java. Show proper reasoning with step by step process. Comment on the code please and show proper indentation. Use simplicity. Must match the exact Output. CODE GIVEN: LineSegment.java LineSegmentTest.java Point.java public class Point { private double x, y; // x and y coordinates of point /** * Creates an instance of Point with the provided coordinates * @param inX the x coordinate * @param inY the y coordinate */ public Point (double inX, double inY) { this.x...

  • Can I get some help with this problem? Can someone show how do this in C?...

    Can I get some help with this problem? Can someone show how do this in C? Thank you for your help. Write a C object-oriented program that reads the coordinates of two points in the plane and shows the distance between them. In order to do that implement the class Point.    Point{       float x;       float y;       Point(): void       set (float x, float y): void       getX( ): float (optional implementation)       getY( ): float (optional...

  • Complete the following coding in java Create a class Circle that represents a round moving dot....

    Complete the following coding in java Create a class Circle that represents a round moving dot. A circle object needs to contain double variables to store the: Current X location of the circle's center Current Y location of the circle's center Radius of the circle Direction of the circle's movement in radians Speed of the circle's movement . . The Circle class must contain a constructor Circle double x, double y, double radius) that initializes the circles center x, y...

  • using python 3: Do not change the tests. Write the body of the distFromOrigin method. class...

    using python 3: Do not change the tests. Write the body of the distFromOrigin method. class Point: def __init__(self, initX, initY): """ Create a new point at the given coordinates """ self.__x = initX self.__y = initY def getX(self): """ Get its x coordinate """ return self.__x def getY(self): """ Get its y coordinate """ return self.__y def __str__(self): """ Return a string representation of self """ return "({}, {})".format(self.__x, self.__y) def distFromOrigin(self): """ Return the distance between self and...

  • (3 pts) Add a Nissan, Sedan, 2019 car to u (3 pts) Add a Ford, Sedan,...

    (3 pts) Add a Nissan, Sedan, 2019 car to u (3 pts) Add a Ford, Sedan, 2018 car to container Dealer o ts) Define/write the fun total Dealer's inventory of vehicles in stock, as well type, bra vehicles. nction named Printinventory(). Function should display nd, model, and year of the 3. Given the class specifications below: Point -x:int-e -y : int +Point (x: int, y: İnt) +getx) :int +setx(x:int):void +getYO:int +setY(y:int):void +setXYCx : int, y int) : void +print():void (36...

  • Write a class called Point that contains two doubles that represent its x- and y-coordinates. It...

    Write a class called Point that contains two doubles that represent its x- and y-coordinates. It should have get and set methods for both fields. It should have a constructor that takes two double parameters and initializes its coordinates with those values. It should have a default constructor that initializes both coordinates to zero. It should also contain a method called distanceTo that takes as a parameter another Point and returns the distance from the Point that was passed as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT