1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rasek [7]
3 years ago
8

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)]"
Computers and Technology
1 answer:
mel-nik [20]3 years ago
4 0

Answer:

import java.awt.Point;

public class Line{

private Point point1, point2;

public Line(Point p1, Point p2){

point1 = p1;

point2 = p2;

}

public Point getP1(){

return point1;

}

public Point getP2(){

return point2;

}

public String toString(){

return "[( The " + point1.x + "," + point1.y + "), (" + point2.x + "," + point2.y +")]";

}

public static void main(String args[]){

Line lineObj = new Line(new Point(7,9), new Point(6,2));

System.out.println(lineObj.toString());

}

}

Explanation:

  • Declare the points inside the class Line.
  • Initialize the getters and setters method for the class.
  • Define a toString method that returns the information in a formatted manner.
  • Inside the main method, initialize an object with some values.
  • Display the information by calling the toString method.
You might be interested in
Why isn't my brainly camera working? I got Brainly Plus and can't even scan questions. I've logged out, I've uninstalled and rei
N76 [4]

Answer:

Try resetting your device.

Explanation:

In order to send and receive iMessages to your iPhone, iMessage must be enabled. By doing this, you will associate your phone number with the email address used for your Apple ID or iCloud account.

8 0
3 years ago
Microsoft word's spell checker
natka813 [3]
A, will also check word usage
7 0
3 years ago
Read 2 more answers
What does UDP stand for?
sleet_krkn [62]
User Datagram Protocol
3 0
3 years ago
Read 2 more answers
Which option ensures that different parts of the document can have different page layouts? ​
Mice21 [21]

Answer:

77777777777777777

Explanation:

8 0
3 years ago
Read 2 more answers
Satırlar ve sütunların kesişmesiyle oluşan kutular aşağıdakilerden hangisidir
Kryger [21]

Answer:

Huh English please......

7 0
3 years ago
Other questions:
  • When did Kodak introduce film photography to the commercial market?
    10·2 answers
  • Complete the paragraph to explain how Angelina can notify readers that her report is just a draft. Angelina has decided to add t
    12·2 answers
  • Which statement prints "hi" on the screen?
    5·2 answers
  • The process of executing a program is also called ________.
    8·1 answer
  • In a proper webpage, which tag holds all of a webpages visble HTML
    12·2 answers
  • There is an interface I that has abstract class AC as its subclass. Class C inherits AC. We know that C delegates to an object o
    12·1 answer
  • First calculating device​
    12·2 answers
  • A typical day in programming and software development would involve
    7·1 answer
  • Also have a good day people !!
    5·2 answers
  • _____ are fields that are used to personalize a mail merge document
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!