Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with writing code to complete the undefined methods in both classes according to the comments I've given for the source files. I

I need help with writing code to complete the undefined methods in both classes according to the comments I've given for the source files. I only have a background in Python (one semester's worth) and my professor wants this done in Java. I can understand Java a little bit but this is really difficult for me.

First source file below ------------ public class Line { private Point p1, p2; /** * Initializes a newly created Line object with the given * values. * * @param x1 and x2 the x coordinates of p1 and p2 * @param y1 and y2 the y coordinates of p1 and p2 */ public Line(int x1, int y1, int x2, int y2) { } /** * Initializes a newly created Line object with the values * from the two input Point objects. * * @param p1 and p2 two Point objects used to initialize * this Line object */ public Line(Point p1, Point p2) { } /** * Calculate the slope of this Line object using the * formula (y1 - y2)/(x1 - x2) * * slope of a vertical line is undefined, that is, x1 and x2 * are equal, throw an ArithmeticException * * @return the slope of this Line object */ public double getSlope() { // TO DO return 0.0; } /** * Calculate the distance between the two points of * this Line object * * @return the distance */ public double getDistance() { // TO DO return 0.0; } /** * Calculate the middle point of this Line object * * @return a Point object */ public Point getMidpoint() { // TO DO return null; } /** * two lines are parallel if they have the same slope, or * if they are both vertical. Note that two slopes are the * same if their difference is very small. * * @param line the other Line object * * @return true if the objects are parallel; false * otherwise. */ public boolean parallelTo(Line line) { // TO DO return false; } /** * Compares this object to the other object. The result is * true if and only if the argument is not null and is a * Line object with the same values as this Line object * * @param obj the object to compare with. * * @return true if the objects are the same; false * otherwise. */ public boolean equals(Object obj) { // TO DO return false; } /** * Returns a String object that represents this Line * * @return a string representation of this Line's value. */ public String toString() { return "[" + p1 + "," + p2 +"]"; } } 

----------------------

Second Source file below

----------------------

public class Point { private int x; private int y; /** * Initializes a newly created Point object with x and y * coordinates set to 0. */ public Point() { } /** * Initializes a newly created Point object with the given * values. * * @param x the x coordinate of this point * @param y the y coordinate of this point */ public Point(int x, int y) { } /** * Initializes a newly created Point object with the values * from the input string. Throws an IllegalArgumentException * if parameter str is a null reference or contains more * than two values; sets both instance variables to zero if * str contains nothing but space characters. * * @param str string containing values of coordinates, such * as "10,20". */ public Point(String str) { } /** * Initializes a newly created Point object with the values * from the input Point object. * * @param other a Point object used to initialize this Point * object */ public Point(Point other) { } /** * Returns the x coordinate of this Point object. * * @return the x coordinate of this object. */ public int getX() { } /** * Returns the y coordinate of this Point object. * * @return the y coordinate of this object. */ public int getY() { } /** * Returns a String object that represents this Point as, * for example, (5, 3) if x is 5 and y is 3. * * @return a string representation of this Point's value. */ public String toString() { // TO DO return null; } /** * Compares this object to the other object. The result is * true if and only if the argument is not null and is a * Point object that contains the same values as this Point * object. * * @param obj the object to compare with. * * @return true if the objects are the same; false * otherwise. */ public boolean equals(Object other) { // TO DO return false; } /** * Returns the Manhattan distance between this Point object * and the other Point object. * * Manhattan distance is the distance between two points if * you walk only in a horizontal or vertical direction. * * @param other the other Point object * * @return the Manhattan distance between this and other * Point objects. */ public int manhattanDistance(Point other) { // TO DO return 0; } } 

-------------------------

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

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions