Question
Urgent!

Consider the following code for the point class studied in week 2: Import math class Point: #static attribute _count = 0 # to
х Question Completion Status: UCHWUCIBURTIES TO self._x=x self_y=y Point_count=1 #updating the point count #updating the Poin
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program

import math
class Point:
#static attribute
__count=0 #to count how many points we have created so far
#initialization method
def __init__(self,x=0,y=0): #defaults arguments technique
self.__x=x
self.__y=y
Point.__count+=1 #updating the point count
#getters
def getX(self):
return self.__x
def getY(self):
return self.__y
def printPoint(self):
return '('+str(self.__x)+','+str(self.__y)+')'
#setters
def setPoint(self,x,y):
self.__x=x
self.__y=y
def reset(self):
self.setPoint(0,0)
#other methods
def distance(self,p):
return math.sqrt((self.getX()-p.getX())**2 + (self.getY()-p.getY())**2)
#static method
def printPointCount():
return Point.__count
def getSlope(self,p): #method to find slope
return ((p.getY()-self.getY())/(p.getX()-self.getX()))
#testing
#creating two Point objects
p1=Point(3,4)
p2=Point(8,6)
print("Slope is ",p1.getSlope(p2)) #calling slope method
  

Screenshot of the code with correct indendation

1 import math 2 - class Point: 3 #static attribute 4 count=0 #to count how many points we have created so far 5 #initializati

Output

Slope is 0.4

If you find this answer useful ,please rate positive, thankyou

Add a comment
Know the answer?
Add Answer to:
Urgent! Consider the following code for the point class studied in week 2: Import math class...
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
  • Need Help! in English Can not get program to run  plz include detailed steps as comments of...

    Need Help! in English Can not get program to run  plz include detailed steps as comments of what i did not do what I have done so far class Point: def __init__(self): self._x = 0 self._y = 0 def getX(self): return self._x def setX(self, val): self._x = val def getY(self): return self._y def setY(self, val): self._y = val def __init__(self, initX = 0, initY = 0): self._x = initX self._y = initY def __str__(self): return '<'+str(self._x)+', '+str(self._y)+ '>' def scale(self, factor):...

  • 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...

  • 11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl...

    11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...

  • 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...

  • What is wrong with the following code: class Point { private : int x, y; public...

    What is wrong with the following code: class Point { private : int x, y; public : Point (int u, int v) : x(u), y(v) {} int getX () { return x; } int getY () { return y; } void setX (int newX ) const { x = newX ; } }; int main () { Point p(5, 3); p.setX (9001) ; cout << p. getX () << ’ ’ << p. getY (); return 0; }

  • Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:

    Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:AdditionSubtractionMultiplicationDivisionModuloExponentThe following source files are already complete and CANNOT be changed:MathQuiz.java (contains the main() method)OperationType.java (defines an enumeration for valid math operations and related functionality)The following source files are incomplete and need to be coded to meet the indicated requirements:MathQuestionable.javaA Random object called RANDOM has already been declared and assigned, and you must not change this assignment in any way.Declare and assign an interface integer called MAX_SMALL and assign it the...

  • Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:

    Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:AdditionSubtractionMultiplicationDivisionModuloExponentThe following source files are already complete and CANNOT be changed:MathQuiz.java (contains the main() method)OperationType.java (defines an enumeration for valid math operations and related functionality)The following source files are incomplete and need to be coded to meet the indicated requirements:MathQuestionable.javaA Random object called RANDOM has already been declared and assigned, and you must not change this assignment in any way.Declare and assign an interface integer called MAX_SMALL and assign it the...

  • Can you tell me if this is right please import java.lang.reflect.AnnotatedArrayType; /** * The class <b>Point</b>...

    Can you tell me if this is right please import java.lang.reflect.AnnotatedArrayType; /** * The class <b>Point</b> is a simple helper class that stares a 2 dimentional element on a grid * * @author Guy-Vincent Jourdan, University of Ottawa */ public class Point { public int dot, row, col;       // ADD YOUR INSTANCE VARIABLES HERE /**    * Constructor    *    * @param x    * the x coordinate    * @param y    * the y coordinate...

  • Java Programming: Math Quiz

    Starting codes:MathQuiz.javaimport java.util.Scanner;public class MathQuiz {    private final int NUMBER_OF_QUESTIONS = 10;    private final MathQuestion[] questions = new MathQuestion[NUMBER_OF_QUESTIONS];    private final int[] userAnswers = new int[NUMBER_OF_QUESTIONS];    public static void main(String[] args) {        MathQuiz app = new MathQuiz();        System.out.println(app.welcomeAndInstructions());        app.createQuiz();        app.administerQuiz();        app.gradeQuiz();    }    private String welcomeAndInstructions() {        return "Welcome to Math Quiz!\n" +         ...

  • 10p Python For the following question, refer to the Python module on the right, as well...

    10p Python For the following question, refer to the Python module on the right, as well as the code below. 1) What is the output of the following code? #dodgeable.py #main dodgeable.py import dodgeable class Locatable: def NUM_CARS = 3 init (self,x,y): NUM TRUCKS = 2 self.mX = X WIDTH = 60 self.mY = y def setx (self,x): def main (): self.mX = x object_list = [] def sety (self, y): self.mY = y for i in range (NUM_CARS) :...

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