Question: Java Please Triangles in a Plane In today's laboratory session, you will write a program that computes various quantities that are used in characterizing a

Java Please Java Please Triangles in a Plane In today's laboratory session, you willwrite a program that computes various quantities that are used in characterizinga triange. Given the three vertices (corners) of a triangle, as three

Triangles in a Plane In today's laboratory session, you will write a program that computes various quantities that are used in characterizing a triange. Given the three vertices (corners) of a triangle, as three points in the cartesian coordinate plane, we can render the triangle. Your program will compute and display various quantities related to a triangle. Definition 1. A triangle is a three-sided polygon. Every triangle has three sides and three vertices, which are noncollinear. Suppose we denote the vertices of a triangle as p1=(x1,y1),p2=(x2,y2), and p3=(x3,y3), where each (xi,yi) represents a point in the cartesian coordinate plane. The Euclidean distance between two points u and v,u=(ux,uy) and v=(vx,vy), denoted uv, is given by the formula below. uv=(uxvx)2+(uyvy)2 Given the vertices of a triangle p1,p2, and p3, its perimeter p is p=p1p2+p1p3+p2p3. The semiperimeter s of a triangle is defined as half its perimeter, s=2p=2p1p2+p1p3+p2p3. An important theorem in plane geometry known as Heron's formula can be used to compute the area of a triangle. Given the lengths of the sides and the semiperimeter s of a triangle, the area is =s(sp1p2)(sp1p3)(sp2p3). DEFINITION 2. The median of a triangle is a line drawn from a vertex of the triangle to the midpoint of the side opposite the vertex. The three medians of a triangle always intersect in the interior of the triangle. DEFINITION 3. The geometric centroid, also known as the median point, of a triangle is the point at which the three medians intersect. Given the vertices of a triangle, p1=(x1,y1),p2=(x2,y2), and p3=(x3,y3), we can calculate its by taking the average of the x coordinates and the y coordinates of all the three vertices. G(x,y)=(3x1+x2+x3,3y1+y2+y3) Figure 1: The Centroid of a Triangle The TriangleSolver Program Write a Java program that prompts the user for the cartesian coordinates of the vertices of a triangle. The program displays the vertices. It then computes and displays the length of the sides, the perimeter, area, and centroid of the triangle to the nearest thousandths. Your program is not required to check whether the points are noncollinear. Typical sample runs of the program should appear as shown below: Listing 1: Sample Run Enter the x-coordinate and y-coordinate of the first vertex 1.54.75 Enter the x-coordinate and y-coordinate of the second vertex 3.24.65 Enter the x-coordinate and y-coordinate of the third vertex 1.785.87 Triangle: p1=(1.500,4.750);p2=(3.200,4.650);p3=(1.780,5.870) Side A=1.702939; side B=1.154; side C=1.872 Perimeter =4.730 Area =0.966 Centroid =(2.160,5.090) Listing 2: Sample Run Enter the x-coordinate and y-coordinate of the first vertex 3.141591.25 Enter the x-coordinate and y-coordinate of the second vertex 3.212.75 Enter the x-coordinate and y-coordinate of the third vertex 1.456.9857 Triangle: p1=(3.142,1.250);p2=(3.200,12.750);p3=(1.450,6.986) Side A=15.369312; side B=8.408; side C=7.406 Perimeter =31.183 Area =14.273 Centroid =(0.464,6.162) Enter the x-coordinate and y-coordinate of the first vertex 3.141591.25 Enter the x-coordinate and y-coordinate of the second vertex 3.212.75 Enter the x-coordinate and y-coordinate of the third vertex 1.456.9857 Triangle: p1=(3.142,1.250);p2=(3.200,12.750);p3=(1.450,6.986) Side A=15.369312; side B=8.408; side C=7.406 Perimeter =31.183 Area =14.273 Centroid =(0.464,6.162) Listing 3: Sample Run Enter the x-coordinate and y-coordinate of the first vertex 0 Enter the x-coordinate and y-coordinate of the second vertex 030 Enter the x-coordinate and y-coordinate of the third vertex 400 Triangle: p1=(0.000,0.000);p2=(0.000,30.000);p3=(40.000,0.000) Side A=30.000000; side B=40.000; side C=50.000 Perimeter =120.000 Area =600.000 Centroid =(13.333,10.000) Listing 4: Sample Run Enter the x-coordinate and y-coordinate of the first vertex 55 Enter the x-coordinate and y-coordinate of the second vertex 0 Enter the x-coordinate and y-coordinate of the third vertex 55 Triangle: p1=(5.000,5.000);p2=(0.000,0.000);p3=(5.000,5.000) Side A=7.071068; side B=14.142; side C=7.071 Perimeter =28.284 Area =0.000 Centroid =(0.000,0.000)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!