Menu
Question Index
...


Write a program to find if the given point lies in a Rectangle. Points are given in anti clock wise direction starting from bottom left point.

Input (Point, Point, Point, Point, Point) Output (boolean)
[1, -4], [4, -4], [4, -2], [1, -2], [2, -3] true
[-2, -2], [2, -2], [2, 2], [-2, 2], [1, -1] true
[-5, 0], [-3, 4], [-6, 6], [-8, 2], [-7, 3] true
[2, -4], [6, -4], [6, -1], [2, -1], [-5, 4] false
[1, 1], [4, 1], [4, 3], [3, 1], [2, 4] false

class IsPointInRectangle

{    public static void main(String s[])
    {
        Point firstPoint = new Point(1, -4);
        Point secondPoint = new Point(4, -4);
        Point thirdPoint = new Point(4, -2);
        Point fourthPoint = new Point(1, -2);
        Point searchPoint = new Point(2, -3);
        System.out.println("Given point lies in the Rectangle : " + isPointInARectangle(firstPoint, secondPoint, thirdPoint, fourthPoint, searchPoint));

    }


public static boolean isPointInARectangle(Point firstPoint, Point secondPoint, Point thirdPoint, Point fourthPoint, Point searchPoint) {
//Write code here to find if the given point is lies in a rectangle.
}

//If required write any additional methods here
}
class Point {

double x;
double y;

Point(double x, double y) {
this.x = x;
this.y = y;
}
}

Doubts

Problems

Topic: Behavior Of Java Classes Using Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App