Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Point{
- private int x, y;
- public Point(){
- x = 0;
- y = 0;
- }
- public Point( int theX, int theY ){
- x = theX;
- y = theY;
- }
- public int getX(){
- return x;
- }
- public int getY(){
- return y;
- }
- public void setX( int theX ){
- x = theX;
- }
- public void setY( int theY ){
- y = theY;
- }
- public String toString(){
- return "(" + x + ", " + y + ")";
- }
- /*Add the following method to the Point class:
- public int quadrant()
- Returns which quadrant of the x/y plane this Point object falls in. Quadrant 1 contains all points whose x and y values are both positive. Quadrant 2 contains all points with negative x but positive y. Quadrant 3 contains all points with negative x and y values. Quadrant 4 contains all points with positive x but negative y. If the point lies directly on the x and/or y axis, return 0.
- */
- public int quadrant(){
- if( y == 0 || x == 0 )
- return 0;
- else if( x > 0 && y > 0 )
- return 1;
- else if( x < 0 && y > 0 )
- return 2;
- else if( x < 0 && y < 0 )
- return 3;
- else
- return 4;
- }
- public void flip(){
- int temp = x;
- x = -y;
- y = -temp;
- }
- /*Add the following method to your Point class:
- public boolean isVertical(Point other)
- Returns true if the given Point lines up vertically with this Point; that is, if their x coordinates are the same.
- */
- public boolean isVertical(Point other){
- if( x == other.getX() )
- return true;
- else
- return false;
- }
- /*Add the following method to the Point class:
- public double slope(Point other)
- Returns the slope of the line drawn between this Point and the given other Point. Use the formula (y2 - y1) / (x2 - x1) to determine the slope between two points (x1, y1) and (x2, y2). Note that this formula fails for points with identical x-coordinates
- */
- public double slope(Point other){
- return (1.0 * y - other.getY())/(1.0 * x - other.getX() );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement