Question: A triangle is is a polygon with three edges and three vertices. It is one of the basic shapes in geometry. We can use


A triangle is is a polygon with three edges and three vertices.It is one of the basic shapes in geometry. We can useHeron's formula to B calculate the perimeter and area of a triangleas shown below: perimeter=a+b+c perimeter 2 S= =s(sa)(sb)(sc) area=S Sample run of

A triangle is is a polygon with three edges and three vertices. It is one of the basic shapes in geometry. We can use Heron's formula to B calculate the perimeter and area of a triangle as shown below: perimeter=a+b+c perimeter 2 S= =s(sa)(sb)(sc) area=S Sample run of the program: Enter the coordinates of triangle ABC x-coordinate of A: 5 y-coordinate of A: 5 x-coordinate of B: 6 y-coordinate of B: 7 x-coordinate of C: 8 A y-coordinate of C: 5 Triangle: A(5,5), B(6,7), and C(8,5) Perimeter = 8.064495 Area = 2.999999 b Write a Java program to prompt user for the coordinates of the three corners of a triangle and calculate its perimeter and its area. a C Would you like to repeat the program (1 for yes, 2 for no)? 2 End of the program. The program should be developed based on the following specifications: Appropriate error messages should be displayed in case of invalid inputs. This should be done by creating and calling a method called verify_input in your program. You may only accept positive integer numbers for the x- and y-coordinates of the three points, ABC. You may only accept the points located on the 40 X 40 grid (min :0, max 40). Your program should be repeated as long as the user wishes. You need to create and use the following methods in your implementation besides any other methods that is needed for this lab assignment. Takes coordinates of (x,y) and returns true, if they are positive, and they are in range [0-40], otherwise it returns false public static boolean verify_input (int x, int y) { } Takes coordinates of two points (x1,y1), (x2,y2), then calculates and returns their distance public static double distance (int x1, int yl, int x2, int y2) { } Takes the three coordinates of the triangle, (xA, yA), (xB, yB), (xC, yC), and returns its perimeter public static double perimeter (int xA, int yA, int xB, int yB, int xC, int yC) { } Takes the three coordinates of the triangle, (xA, yA), (xB, yB), (xC, yC), and returns its area public static double area (int xA, int yA, int xB, int yB, int xC, int yC) { } The sample run of the program follows. The values indicated as bold are the values entered by the user. Enter the coordinates of triangle ABC x-coordinate of A: 5 y-coordinate of A: 5 x-coordinate of B: 6 y-coordinate of B: 7 x-coordinate of C: 8 y-coordinate of C: 5 Triangle: A(5, 5), B(6, 7), and C(8, 5) Perimeter = 8.064495 Area = 2.999999 Would you like to repeat the program (1 for yes, 2 for no)? 1 Enter the coordinates of triangle ABC x-coordinate of A: 5 y-coordinate of A: 50 x-coordinate of B: 6 y-coordinate of B: -7 x-coordinate of C: 8 y-coordinate of C: 5 coordinate (5,50) is not in acceptable range coordinate (6,-7) is not in acceptable range Would you like to repeat the program (1 for yes, 2 for no)? 2 End of the program. Bonus: [5 marks]: Reject the input if the three points make a line and not a triangle. For this part you need to create following method and use it in your program. Takes the the three coordinates of the triangle, (xA, yA), (xB, yB), (xC, yC), and returns true if they located on a single line, otherwise it returns false public static boolean isLine (int xA, int yA, int xB, int yB, int xC, int yC) { } Note that you need to define a small value as EPSILON to deal with this problem. Refer to sample solution of you Lab2.java assignment.

Step by Step Solution

3.31 Rating (148 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

FileName TrianglePerimeterAreajava import javautilScanner public class TrianglePerimeterArea public ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!