I need help coding this with Python.
Create a Point class that consists of an ordered pair (x, y) representing a point's location on the x and y axes. The constructor allow the x and y values to be passed in and should default missing values to 0. You must override the __str__ method to print the point as normal (i.e., "(2, 5)").
Also, create a Line class that consists of a pair of Point objects p and q. A line can be instantiated in one of two ways, as shown below.
somePoint = Point(2, 3)
anotherPoint = Point(4, 8)
someLine = Line(somePoint, anotherPoint)
or...
someLine = Line()
In the second case, the constructor should initialize both points to the origin (0, 0). You must override the __str__method to print the line as follows: "(2, 5)--(4, 7)". Your class must also provide a length method that returns the length of the segment.
Thanks for the question.
Below is the code you will be needing Let me know if you have any doubts or if you need anything to change.
Thank You !
===========================================================================
class Point():
def __init__(self, x=0, y=0):
self.x_coordinate = x
self.y_coordinate = y
def __str__(self):
return '({},{})'.format(self.x_coordinate, self.y_coordinate)
class Line():
def __init__(self, start=Point(), end=Point()):
self.start = start
self.end = end
def __str__(self):
return '{}-{}'.format(self.start, self.end)
def length(self):
square_sum = (self.start.x_coordinate - self.end.x_coordinate) ** 2
square_sum += (self.start.y_coordinate - self.end.y_coordinate) ** 2
return square_sum**0.5
def main():
somePoint = Point(2, 3)
anotherPoint = Point(4, 8)
someLine = Line(somePoint,anotherPoint)
print(someLine)
print('Lengh: {}'.format(someLine.length()))
main()
=======================================================================


I need help coding this with Python. Create a Point class that consists of an ordered...
Create a new class called Point that represents a point in the Cartesian plane with two coordinates. Each instance of Point should have to coordinates called x and y. The constructor for Point should take two arguments x and y that represent the two coordinates of the newly created point. Your class Point should override the __str__(self) method so that it returns a string showing the x- and y-coordinates of the Point enclosed in parentheses and separated by a comma....
Create an application that provides a solution for problem 20.8 In addition to requirements specified in the description. The class must satisfy the following Default Constructor Two argument constructor for data used to initialize "first" and "second" "toString" method for displaying the "first" and "second" data elements Creates a "Comparator" object (to be used by the sort method; i.e. create an instance of a class that implements the interface [must override "compare" and "equals" methods]) The application must create an...
Need Help with these questions for coding.
This is the signature of a constructor for the Person class. public Person private Person () public Object Person () O public Person () Question 3 (1 point) This element of a class allows properties to be pre-loaded as an object of the class is being instantiated. methods attributes constructors properties Question 4 (1 point) If you create a Parce method to take a record from a file and create an object of...
In python create a TaxReturn class with attributes that hold a taxpayer's Social Security number, last name, first name, street address, city, state, zip code, annual income, marital status, and tax liability. Include a constructor that requires arguments that provide values for all the fields other than the tax liability. The constructor calculates the tax liability based on annual income and the percentages in the following table: Income($) Single Married 0 - 20,000 15% 14% 20,001 - 50,000 22% 20%...
Draw the UML DIAGRAM ALSO
PLEASE DRAW THE UML DIAGRAM.ALSO
in java
should use the program in java
For this task you will create a Point3D class to represent a point that has coordinates in three dimensions labeled x, y and z. You will then use the class to perform some calculations on an array of these points. You need to draw a UML diagram for the class (Point3D) and then implement the class The Point3D class will have the...
Programming in C# Create a Money class that has as data members dollars and cents. Include IncrementMoney and DecrementMoney instance methods. Include constructors that enable the Money class to be instantiated with a single value representing the full dollar/cent amount as well as a constructor that enables you to create an instance of the class by sending two separate integer values representing the dollar and cent amounts. Include an instance method that returns as a string the number of dollars,...
In JAVA Design a class named Point that meets the following requirements: Two data fields x and y for representing a point with getter methods. A no-arg constructor that constructs a point for (0, 0). A constructor that constructs a point with the specified x and y values. Override the equals method. Point p1 is said to be greater than point p2 if p1.x == p2.x and p1.y == p2.y. Implement the Comparable<Point> interface and the compareTo method. Point p1...
Need help finishing this code # Description : The Pet class contains fields for name, pet # type,and age. The age field is the age now # or age of pet when it passed away. (These # are all dogs I have had.) There is a static or # class variable called number_pets that # tracks how many instances have been created. # The constructor will fill all fields and add # one to the number_pets variable. # The special...
Help with this coding assignment for C++! Add any comments for
better understanding.
Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The constructor will initial all member variable to a default value 0. • One public pure virtual function showingredients() that returns void....
Create an Item class, which is the abstract super class of all Items. Item class includes an attribute, description of type String for every item. [for eg. Book] A constructor to initialize its data member of Item class. Override toString() method to return details about the Item class. Create the ExtraCharge interface with the following details. Declare a constant RATE with value 0.25 Declare a method called calculateExtraCharge(), which returns a double value. Create the...