Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package test; public class Point { // data fields private double x, y; //Constructor1 public Point(){ x = 0; y = 0; } // Constructor2

image text in transcribed
image text in transcribed
package test;
public class Point {
// data fields
private double x, y;
//Constructor1
public Point(){
x = 0;
y = 0;
}
// Constructor2
public Point(double x, double y){
this.x = x;
this.y = y;
}
// Members
// getters
public double getX(){
return x;
}
public double getY(){
return y;
}
// setters
public void setX(double newX){
this.x = newX;
}
public void setY(double newY){
this.y = newY;
}
public void move(double newX, double newY){
this.x = newX;
this.y = newY;
}
public void display(){
System.out.println("(" + this.x + ", " + this.y + ")");
}
public String toString() {
return "("+x+", "+y+")";
}
// driver-method
public static void main(String[] args){
Point p1 = new Point();
Point p2 = new Point(3, 4);
p1.display();
p2.display();
}
}
Problem 2. Point and Line Class Please first download the attached Point.java file which contains the definition for the point class. Read the codes and understand what the data fields and methods the point class has. Given the UML, diagram in the following Fig2, define and implement the Line class, two of whose data fields are two Point objects. Write the client program named Line Test.java to test the methods of the Line class Line -start: Point -end: Point -slope: double -intercept: double +Line) +Line(pl: Point, p2: Point) +move(double double y) *getLength(): double +isParallelother: Line):bool +getslope(): double +getintercept(): double intersectionPoint(other: Line):Point 1) move() function will move both the start Point and end point by x and y accordingly. 2) getLength() computs and returns the length of this line. It is known that the length of a line can be computed as length = (start.x-end. x)+ start.y-end.') 3) The slope of a line can be determined by: slope = (end.y-starty)/(end.x-start.x) 4) The intercept of a line can be determined by: intercepta starty - slopestart.x 5) Two lines will be parallel is they have the same slope but different intercept. 6) If two lines (linel and line2) are not parallel, they will be intersected. The intersection point (p) can be determined by: p.x = (line2.intercept-line.intercept)/(line slope-line2 slop) py = line 1.slope *px + line intercept Outputs: For Line 1: Please enter the x and y coordinates for Point 1:11 Please enter the x and y coordinates for Point 2:48 The length of this line is: 7.6158 The slope of this line is: 2.3333 The intercept of this line is: -1.3333 For Line 2: Please enter the x and y coordinates for Point 1:25 Please enter the x and y coordinates for Point 2:32 The length of this line is: 3.1623 The slope of this line is: -3 The intercept of this line is: 11 Line 1 and Line 2 is not parallel They will intersect at Point: (2.3125, 4.0625)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions