Question: Write a program that enables the user to drag the vertices of a triangle and displays the angles dynamically as the triangle shape changes, as
Write a program that enables the user to drag the vertices of a triangle and displays the angles dynamically as the triangle shape changes, as shown in Figure 15.30a. The formula to compute angles is given in Listing 4.1.
(a) Exercise enables the user to drag vertices and display the angles dynamically.
Listing
![{ 4 public static void main(String[] args) { 5 Scanner input =](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2022/11/636a7348ad065_712636a73489c4bb.jpg)

101.93 34.53 43.54 (a) 1 import java.util.Scanner; 2 3 public class ComputeAngles { 4 public static void main(String[] args) { 5 Scanner input = new Scanner (System.in); 6 // Prompt the user to enter three points System.out.print("Enter three points: "); double x1 = input.nextDouble(); double yl = input.nextDouble(); double x2 = input.nextDouble(); double y2 = input.nextDouble(); double x3 = input.nextDouble(); double y3 = input.nextDouble(); 8. 9. 10 11 12 13 14 15 16 17 18 19 20 21 22 // Compute three sides double a = Math.sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3)); double b Math.sqrt((x1 - x3) * (x1 - x3) + (yl - y3) * (yl - y3)); double c - + (yl - y2) * (yl - y2)); Math.sqrt((x1 - x2) (1 - 2) 23 // Compute three angles double A = 24 Math.toDegrees (Math.acos ((a / (-2 * b * c))); double B = Math.toDegrees (Math.acos((b / (-2 * a * c))); double C = Math.toDegrees (Math.acos((c * c - b * b - a * a) / (-2 * a * b))); 25 26 27 c) 28 29 30 31 // Display results System.out.println("The three angles are Math.round(A * 100) / 100.0 + " " + 32 33 34 NNNN NNNN NNM mmmm
Step by Step Solution
3.50 Rating (167 Votes )
There are 3 Steps involved in it
Program Plan The program creates a right angle triangle with the circles as points or as the vertice... View full answer
Get step-by-step solutions from verified subject matter experts
