subject

Write a class called Line that represents a line segment between two Points. Your Line objects should have the following methods:
public Line(Point p1, Point p2)
Constructs a new Line that contains the given two Points.
public Point getP1()
Returns this Line's first endpoint.
public Point getP2()
Returns this Line's second endpoint.
public String toString()
Returns a String representation of this Line, such as "[(22, 3), (4, 7)]".

B) Add the following accessor method to your Line class:
public double getSlope()

Returns the slope of this Line. The slope of a line between points (x1, y1) and (x2, y2) is equal to (y2 – y1) / (x2 – x1). If x2equalsx1 the denominator is zero and the slope is undefined, so you may throw an exception in this case.

C) Add the following constructor to your Line class:
public Line(int x1, int y1, int x2, int y2)

Constructs a new Line that contains the given two Points.

D) Add the following accessor method to your Line class:
public boolean isCollinear(Point p)

Returns true if the given Point is collinear with the Points of this Line —that is, if, when this Line is stretched infinitely, it would eventually hit the given Point

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 13:00
Which of the following statements is false? a. a class can directly inherit from class object. b. if the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly. c. a class's instance variables are normally declared private to enforce good software engineering. d. it's often much more efficient to create a class by inheriting from a similar class than to create the class by writing every line of code the new class requires.
Answers: 3
question
Computers and Technology, 23.06.2019 16:00
Does read theory have answers keys ?
Answers: 1
question
Computers and Technology, 24.06.2019 03:30
The footer area of a web page generally houses which website feature? terms of use web page content business name or title menu headings
Answers: 1
question
Computers and Technology, 24.06.2019 05:00
Who is most likely be your target audience if you create a slide presentation that had yellow background and purple text
Answers: 2
You know the right answer?
Write a class called Line that represents a line segment between two Points. Your Line objects shoul...
Questions
question
Mathematics, 08.01.2021 02:10
question
Mathematics, 08.01.2021 02:10
question
Mathematics, 08.01.2021 02:10
question
Mathematics, 08.01.2021 02:10
Questions on the website: 13722362