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
-
The 3 0 mm - diameter A - 3 6 ?steel rod is subjauted to the axial force shown. Determine the displacement of and C with respect to the fixed support A . ?Es = 2 0 0 GPa ) ?Draw a diagram of normal...
-
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...
-
A hedge trimmer has a blade that moves back and forth with a frequency of 28 Hz. The blade motion is converted from the rotation provided by the electric motor to an oscillatory motion by means of a...
-
In Problems 1 22, use the Principle of Mathematical Induction to show that the given statement is true for all natural numbers n. 1 + 4 + 7 + + (3n - 2) = + (3n 2) = n(3n 1) -
-
What is a preference share and why might a company favour this form of finance?
-
Barbri Company ordinarily pays its employees on a weekly basis. Recently, one of the employees, Bernard Nagle, was sent from the home office on a three-week rip. Nagle has now returned to the office,...
-
Assume you make the following investments Part 1 of 3 O Points: 0 of 2 You invest a lump sum of $7.250 for three years at 14% interest What is the investment's value at the end of three years? In a...
-
Fourth-Sixth-Twelfth Bank currently pays an annuall dividend of $1.40 per share. After extensive analysis, you forecast that the Bank's stock will continue to pay the $1.40 dividend for four years....
-
A rigid, well-insulated tank contains air. A partition in the tank separates 12 ft of air at 14.7 lbf/in., 40F from 10 ft of air at 50 lbf/in., 200F, as illustrated in Fig. P6.46. The partition is...
-
What is the future equivalent of \($1,000\) invested at 8% simple interest for 3 years?
-
In the decision-making process, what are the ways in which context can impact outcomes?
-
What lump-sum amount of interest will be paid on a \($10,000\) loan that was made on 1 June 2011 and repaid on 1 September 2015, with ordinary simple interest at 10% per year?
-
It seems that there are many ways for fraud and abuse to take place in the field of accounting. How can this occur when there are so many regulatory bodies and professional accounting standards in...
-
We live in a global economy, and many different external activities have an impact on the business. On what basis would we narrow the scope of this book to de-emphasize tax law, currency exchange,...
-
Blue Dog Inc. is a leading manufacturer in the high-end sunglasses industry. Blue Dog Inc. reached record revenue levels of over $250 million last year. The company is currently deciding on the...
-
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 financial statements for the Columbia Sportswear Company can be found in Appendix A at the end of this book. You are considering an investment in Columbia Sportswear after a recent outdoor trip...
-
Crescent Paints, Inc., a paint manufacturer, has been in business for five years. The company has had modest profits and has experienced few operating difficulties until this year, 2019, when...
-
Listed below are selected financial data for three corporations: Honeywell International, Inc. (environmental controls), The Dow Chemical Company (chemicals and plastic products), and Abbott...
Study smarter with the SolutionInn App