A triangle is is a polygon with three edges and three vertices. It is one of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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(s—a)(s−b)(s—c) 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. 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(s—a)(s−b)(s—c) 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.
Expert Answer:
Answer rating: 100% (QA)
FileName TrianglePerimeterAreajava import javautilScanner public class TrianglePerimeterArea public ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Let r and s be solutions to the quadratic equation x 2 b x + c = 0. For n N, define d0 = 0 d1 = r s dn = b dn1 c dn2 (n 2) Prove that dn = r n s n for all n N. [4 marks] (b) Recall that a commutative...
-
Predictive text entry systems are familiar on touch screens and mobile phones. This question asks you to consider how the same principles might be used in a programming editor for creating Java code....
-
1. Suppose that a stoichiometric mixture of isooctane (C8H18) and air is burned in an engine and then the fuel is changed to 10% (by liquid volume) ethanol and 90% by liquid volume isooctane. If the...
-
On April 1, Adventures Travel Agency, Inc. commenced operations. These transactions were completed during the month: 1. Issued common shares for $24,000 cash. 2. Obtained a bank loan for $7,000. 3....
-
Lois and Clark are covering separate stories and have to travel in opposite directions. Lois leaves the Daily Planet building at 8:00 a.m. and travels at 35 mph. Clark leaves at 8:15 a.m. and travels...
-
Petitioner Atlantic Marine Company was a contractor located in Virginia. It entered into a subcontract with J-Crew Management, Inc., a Texas corporation, that contained a forum-selection clause...
-
Erie Company manufactures a small CD player called the Jogging Mate. The company uses standards to control its costs. The labor standards that have been set for one Jogging Mate CD player are as...
-
Shelby Woods owns and operates an ice cream factory, the finest of its kind in all the world. Given that pints of ice cream are meant to be identical (for the same flavor), her company uses process...
-
The lift, drag and momentum coefficients for NACA 2412 aerofoil about the quarter chord as a function of angle of attack as shown in the following table. a (degree) C Cd Cm.c/4 -2 0.05 0.006 -0.042 0...
-
Blue Rock. Inc. experienced a casualty loss in 2 0 2 1 . Their warehouse was completely destroyed. Their adjusted basis in the warehouse was $ 7 0 0 , 0 0 0 . The fair market value before the...
-
A bicyclist coasts down a 5.0 degree hill at a steady speed of 7.0 m/s. Assuming a total mass of 95 kg (bicycle plus rider), what must be the cyclist's power output to climb the same hill at the same...
-
There is much concern that immigrants from foreign countries flood the job market, raising unemployment and keeping wages down for American workers. Read the case study "Does Immigration Benefit the...
-
$2 000 000 debentures with a coupon rate of 14% per annum and 10 years to maturity. The current market yield for similar debentures is 12%. Calculate the value of the debentures?
-
Assume that you have been hired as a consultant by Julie Amara to help her and Ben Kay. She has asked you for your help on the GAAP income statements and the legal issues arising from the lease...
-
Your employer, a large MNC, has asked you to assess its transaction exposure. Its projected cash flows are as follows for the next year: Danish krone inflows equal DK38,000,000, while outflows equal...
-
Nate prepares slides for his microscope. In 1 day he prepared 12 different slides. Which equation best represents y, the total number of slides Nate prepares in x days if he continues at this rate? A...
-
Suppose the U.S. government imposes a $1 per gallon of milk tax on dairy farmers. Using the demand and supply equations from question 1: a. What is the effect of the tax on the supply equation? The...
-
In 2007 the hourly cost to employers per German industrial worker was $51. The hourly cost to employers per U.S. industrial worker was $31, while the average cost per Taiwanese industrial worker was...
-
Apartments in New York City are often hard to find. One of the major reasons is rent control. (Difficult) a. Demonstrate graphically how rent controls could make apartments hard to find. b. Often one...
-
The transfer function of a dynamic system is given by \[G(s)=\frac{s+1}{4 s^{4}+5 s^{3}+2 s^{2}+s+6} \] a. Using Routh's stability criterion, determine the stability of the system. b. Using MATLAB,...
-
Figure 10.40 shows a negative feedback control system. a. Design a P controller such that the damping ratio of the closed-loop system is 0.5 . b. Estimate the rise time, overshoot, and \(2 \%\)...
-
Consider the feedback system shown in Figure 10.26. a. Using Routh's stability criterion, determine the range of the control gain \(K\) for which the closed-loop system is stable. b. Use MATLAB...
Study smarter with the SolutionInn App