Menu
Question Index
...


Write a program to find the largest acute triangle which can be formed using the points from the given list. The points p1, p2, p3 in the returned triangle, should be in the same order as the input list. Also implement the equals method in the Triangle class such that the triangles are considered equal when points in both the triangles are same irrespective of their order.

Input (List) Output (Triangle)
{[71,1], [0,70], [12,5], [72,9], [0,55], [13,2], [0,0], [11,2]} {[0,70] - [72,9] - [0,0]}
{[-225, 100], [-175, 0], [0, 50], [300, 0], [30, 45], [20, 20], [-50, 25], [-75, 125]} {[-175,0] - [20,20] - [-75,125]}
{[0, 0], [10, 0], [5, 8], [50, 0], [25, 43], [2, 3], [4, 4]} {[0,0] - [50,0] - [25,43]}
{[2, 3], [4, 3], [6, 6], [3, 18], [2, 14], [5, 0], [-1, -3], [-8, 4], [-4, 2]} {[3,18] - [5,0] - [-8,4]}
{[0, -63], [63, -63], [99, -18], [-9, 63], [-27, 45], [-72, 27], [63, -117], [-63, -117]} {[99,-18] - [-72,27] - [-63,-117]}
{[0, 10], [25, 18], [32, 45], [28, 66], [29, 33], [11, 18]} null

class FindLargestAcuteTriangle

{    public static void main(String s[])
    {
        List points = new ArrayList();
        points.add(new Point(71, 1));
        points.add(new Point(0, 70));
        points.add(new Point(12, 5));
        points.add(new Point(72, 9));
        points.add(new Point(0, 55));
        points.add(new Point(13, 2));
        points.add(new Point(0, 0));
        points.add(new Point(11, 2));
        System.out.println("Largest Acute Triangle is : " + getLargestAcuteTriangle(points));

    }


public static Triangle getLargestAcuteTriangle(List<Point> points) {
//Write code here to get the largest acute triangle.
}
}
class Point {

int x;
int y;

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

@Override
public String toString() {
return "[" + x + "," + y + "]";
}
}

class Triangle {

Point p1;
Point p2;
Point p3;

public Triangle(Point p1, Point p2, Point p3) {
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
}

@Override
public String toString() {
return "{" + p1 + " - " + p2 + " - " + p3 + "}";
}

//If required write any additional methods here
//Implement the equals method here such that the triangles are considered equal when all the points are equal
}

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App