# Answered Essay: I don't know how to do this coding homework and it is due tomorrow, please help

I don’t know how to do this coding homework and it is due tomorrow, please help

Classes and Interfaces

Write each of the following:

A class Point to represent points in a two-dimensional plane. Each point has an x and a y coordinate, determined at creation time, and provides at least the following methods:

double getX(); // return x-coordinate of point

double getY(); // return y-coordinate of point

double distance(Point other); // computes and returns the distance from this point to another point

String toString(); // returns the string “(x,y)”

void draw(); // calls StdDraw.point(x, y)

The distance between two points is given by the square root of (x1 – x2)2 + (y1 – y2)2

Before drawing a point, it might be helpful to call StdDraw.setPenRadius(0.05) and StdDraw.setPenColor. StdDraw is available from http://introcs.cs.princeton.edu/java/stdlib/StdDraw.java (copy and paste into a file)

If you find it helpful for the rest of the assignment, you may implement additional methods in the Point class, beyond the ones required above.

An interface SegmentInterface to represent line segments in the two-dimensional plane. Each line segment has two endpoints, initialized at creation time, and provides at least the following methods:

Point left(); // the point at the left end of the segment

Point right(); // the point at the right end of the segment

Point upper(); // the point at the upper end of the segment

Point lower(); // the point at the lower end of the segment

double length(); // return the length of the segment, that is, the distance between its endpoints

void draw(); // draw the line segment

For horizontal segments the upper and lower methods may return either endpoint, and for vertical segments the left and right methods may also return either endpoint.

A class Segment that implements SegmentInterface, and also provides these additional methods:

boolean isHorizontal();

boolean isVertical();

void move(Point newLowerOrLeft);

String toString();

The move method changes the position of the entire segment by moving the lower point to the new position. In other words, the entire segment moves, without changing its length or angle, so that the lower point is in the new position. For horizontal segments (where both endpoints have the same y coordinate), it moves the left point to the new position.

The toString method returns the string “(x1,y1)(x2,y2)”, where (x1,y1) is the lower endpoint of the segment (the left endpoint for horizontal segments).

The draw method calls StdDraw.line

A class CreateSegments that has the following:

A method printFour to print the values of 4 segment variables, that is, one method that takes four SegmentInterface variables as parameters and prints all four.

A method static void unitTest (); with all of the following:

Two variables declared as SegmentInterface, one of them with coordinates (0.1,0.2)(0.4,0.5), the other (0.1,0.2)(0.4,0.2)

Two variables declared as Segment, one of them with coordinates (0.4,0.5)(0.4,0.2), the other (0.5,0.5)(0.7,0.15)

code to:

print the four segment (including SegmentInterface) variables, then

draw the four segment variables, then

move the last segment to the left by 0.3 units, so its endpoints become (0.2, 0.5)(0.4, 0.15), and

print all the segment variables again, then

draw all the segment variables again.

For each class (except CreateSegments), you will have to provide one or more constructors that take the appropriate parameters, as well as a default (no-arguments) constructor that initializes all coordinates to zero.

In order to test your code, you will have to create a main method in a different class. That main method calls CreateSegment.unitTest();

Turning in the Assignment

Email your source code to the TA.

Do not turn in your main method, or any other test code other than the unit test.

Test.java
——————————————————–
public class Test {

// Invoked when first run
public static void main (String[] arguments) {
Point nothingP = new Point();
Point aP = new Point(1,1);
Point bP = new Point(2,1);
System.out.println(“X of aP is: ” + aP.getX());
System.out.println(“Y of aP is: ” + aP.getY());
System.out.println(“X of bP is: ” + bP.getX());
System.out.println(“Y of bP is: ” + bP.getY());
System.out.println(“Distance between aP and bP: ” + aP.distance(bP));
System.out.println(“String of aP and bP: ” + aP.toString() + ” “+ bP.toString());
System.out.println(“String of nothingP ” + nothingP.toString());

Segment nothingS = new Segment();
Segment aS = new Segment(aP, bP);
System.out.println(“nothingS is horizontal check ” + nothingS.isHorizontal());
System.out.println(“aS is horizontal check ” + aS.isHorizontal());
System.out.println(“nothingS is vertical check ” + nothingS.isVertical());
System.out.println(“aS is vertical check ” + aS.isVertical());
System.out.println(“aS left point ” + aS.left());
System.out.println(“aS right point ” + aS.right());
System.out.println(“aS upper point ” + aS.upper());
System.out.println(“aS lower point ” + aS.lower());
System.out.println(“aS length ” + aS.length());
System.out.println(“aS to string ” + aS.toString());
Point newOne = new Point(4,5);
aS.move(newOne);
System.out.println(“aS moved to new point ” + aS.toString());
Point newTwo = new Point(3,4);
aS.move(newTwo);
System.out.println(“aS moved to new point ” + aS.toString());
System.out.println(“Unit Test: “);
CreateSegments.unitTest();
}
}
—————————————————————————-
Point.java
——————————————-
public class Point {

// Values for the coordinates X and Y
private double x, y;

// Sets X and Y when both are given
public Point(double X, double Y) {
x = X;
y = Y;
}

// Set X and Y to 0 when no arguments are given
public Point() {
x = 0;
y = 0;
}

// Simple getter function for X
public double getX() {
return x;
}

// Simple getter function for Y
public double getY() {
return y;
}

// Computes and returns the distance from this point to another
public double distance(Point other) {
double x12 = x – other.getX();
double y12 = y – other.getY();
x12 = Math.pow(x12,2);
y12 = Math.pow(y12,2);
return Math.sqrt(x12+y12);
}

// Returns the string “(x,y)”
public String toString() {
String points= “(” + x + “,” + y + “)”;
return points;
}
}
—————————————————————————
Segment.java
—————————————-
public class Segment implements SegmentInterface{

private Point a, b;

// Creates a segment with new points at (0,0)
public Segment() {
a = new Point(0,0);
b = new Point(0,0);
}

// Sets Points a and b to two points added at creation
public Segment(Point A, Point B) {
a = A;
b = B;
}

// Sets Points a and b given coordinates of two points
// Use in the form Segment(X1,Y1,X2,Y2)
public Segment(double x1, double y1, double x2, double y2) {
a = new Point(x1,y1);
b = new Point(x2,y2);
}

// The point at the left end of the segment
// If both point’s X coordinates are equal then chooses A

public Point left() {
if(a.getX() > b.getX()) {
return b;
}
else {
return a;
}
}

// The point at the right of the segment
// If both point’s x coordinates are equal then chooses A
public Point right() {
if(a.getX() < b.getX()) {
return b;
}
else {
return a;
}
}

// The point at the top of the segment
// If both point’s y coordinates are equal then chooses A
public Point upper() {
if(a.getY() < b.getY()) {
return b;
}
else {
return a;
}
}

// The point at the botom of the segment
// If both point’s y coordinates are equal then chooses A
public Point lower() {
if(a.getY() > b.getY()) {
return b;
}
else {
return a;
}
}

// The length of the segment using Point.distance
// If points on the same spot then return 0
public double length() {
return a.distance(b);
}

// Determine if a segment is horizontal and returns true if so
public boolean isHorizontal() {
return a.getX() == b.getX();
}

// Determine if a segment is vertical and returns true if so
public boolean isVertical() {
return a.getY() == b.getY();
}

// Moves the entire segment to a new point by moving the lower point
// to the new position. If segment is horizontal then it moves the left
// point to the new position.
public void move(Point newLowerorLeft) {
boolean moveA;
double diffX, diffY, newX, newY;
// Horizontal
if(a.getY() == b.getY()) {
// a is on the left
if(a.getX() < b.getX()) {
moveA = true;
}
// b is on the left
else {
moveA = false;
}
}
// a is lower
else if(a.getY() < b.getY()) {
moveA = true;
}
// b is lower
else {
moveA = false;
}
// use a as the new point
if(moveA) {
diffX = a.getX() – newLowerorLeft.getX();
diffY = a.getY() – newLowerorLeft.getY();
newX = b.getX()-diffX;
newY = b.getY()-diffY;
a = newLowerorLeft;
b = new Point(newX, newY);
}
// use b as the new point
else {
diffX = b.getX() – newLowerorLeft.getX();
diffY = b.getY() – newLowerorLeft.getY();
newX = a.getX()-diffX;
newY = a.getY()-diffY;
a = new Point(newX, newY);
b = newLowerorLeft;
}
}

// Returns a string in form “(x1,y1)(x2,y2)”, where (x1,y1) is the
// lower or left most point
public String toString() {
String seg;
double x1, x2, y1, y2;
if(a.getY() == b.getY()) {
if(a.getX() < b.getX()) {
x1 = a.getX();
x2 = b.getX();
y1 = a.getY();
y2 = b.getY();
}
else {
x1 = b.getX();
x2 = a.getX();
y1 = b.getY();
y2 = a.getY();
}
}
else if(a.getY() < b.getY()) {
x1 = a.getX();
x2 = b.getX();
y1 = a.getY();
y2 = b.getY();
}
else {
x1 = b.getX();
x2 = a.getX();
y1 = b.getY();
y2 = a.getY();
}
seg = “(” + x1 + “,” + y1 + “) (” + x2 + “,” + y2 + “)”;
return seg;
}
}
———————————————————————————————
CreateSegments.java
——————————————-
public class CreateSegments {

// Print the values of 4 segment variables that takes four SegmentInterface variables
// as parameters
public static void printFour(SegmentInterface aSI, SegmentInterface bSI, SegmentInterface cSI, SegmentInterface dSI) {
System.out.println(aSI.toString() + “n” + bSI.toString() + “n” + cSI.toString() + “n” + dSI.toString());
}

public static void unitTest() {
SegmentInterface aSI = new Segment(1,2,4,5);
SegmentInterface bSI = new Segment(1,2,4,2);
Segment aS = new Segment(4,5,4,2);
Segment bS = new Segment(0,0,7,1.5);
CreateSegments.printFour(aSI, bSI, aS, bS);
Point movement = new Point(-5.3, 0);
bS.move(movement);
CreateSegments.printFour(aSI, bSI, aS, bS);
}
}
—————————————————————————————–
SegmentInterface.java
—————————————-
public interface SegmentInterface {
Point left();       // the point at the left end of segment
Point right();       // the point at the right end of the segment
Point upper();       // the point at the upper end of the segment
Point lower();       // the point at the lower end of the segment
double length();   // the length of the segment, that is, the
//   distance between its endpoints
}  Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons: Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed. Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time. Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free. Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time. Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied. Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

## Calculate the price of your order

Total price:
\$0.00

How it works?

Follow these simple steps to get your paper done Fill in the order form and provide all details of your assignment. Proceed with the payment

Choose the payment system that suits you most. Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.  ## Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.  Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.  Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.  