Write a program to allow the user to create an triangle and calculate the area. The...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program to allow the user to create an triangle and calculate the area. The program will prompt the user to enter the x-coordinate and y-coordinate of each vertex (tip) of the triangle. After that, the program will compute and display the triangle (appropriate information) and the area. The program will allow the user to repeat the process until he decides to quit. You will decide how to prompt the user and how to end the loop. The diagram below explains how to compute the triangle area based on the length of the sides. a C b a+b+c 1. Work out s = 2 - - 2. Area =s(s a)(s b)(s c) Your program will consist of three classes (or more depends on your design). class Point Instance variables x and y representing the x-coordinate and y-coordinate of a point. Constructor The constructor will receive 2 parameters and initialize the instance variables accordingly. Get/set methods Please include appropriate methods. Instance method getDistance Parameters: An instance of Point Returns: The distance between this point and the point represented by the parameter. Instance method Example: Point p1 = ... Point p2 = ... double distance = p1.getDistance(p2); toString Parameters: None Returns: A descriptive String class Triangle Instance variables 3 instance variables of Point to represent the 3 vertices of the triangle Constructor Get methods The constructor will receive appropriate parameters for initializing the instance variables. You may define multiple constructors if you deemed fit. Please include appropriate methods. getArea Instance method Parameters: None Returns: Area of the triangle toString Instance method Parameters: None Returns: A descriptive String. class Static method XX_YourName_Lab4 where XX is your tutorial class (e.g. T1, T2, etc.) main Prompts user to enter information of a triangle. Displays the triangle (appropriate information) and the area. Allows user to repeat until he decides to quit. Write a program to allow the user to create an triangle and calculate the area. The program will prompt the user to enter the x-coordinate and y-coordinate of each vertex (tip) of the triangle. After that, the program will compute and display the triangle (appropriate information) and the area. The program will allow the user to repeat the process until he decides to quit. You will decide how to prompt the user and how to end the loop. The diagram below explains how to compute the triangle area based on the length of the sides. a C b a+b+c 1. Work out s = 2 - - 2. Area =s(s a)(s b)(s c) Your program will consist of three classes (or more depends on your design). class Point Instance variables x and y representing the x-coordinate and y-coordinate of a point. Constructor The constructor will receive 2 parameters and initialize the instance variables accordingly. Get/set methods Please include appropriate methods. Instance method getDistance Parameters: An instance of Point Returns: The distance between this point and the point represented by the parameter. Instance method Example: Point p1 = ... Point p2 = ... double distance = p1.getDistance(p2); toString Parameters: None Returns: A descriptive String class Triangle Instance variables 3 instance variables of Point to represent the 3 vertices of the triangle Constructor Get methods The constructor will receive appropriate parameters for initializing the instance variables. You may define multiple constructors if you deemed fit. Please include appropriate methods. getArea Instance method Parameters: None Returns: Area of the triangle toString Instance method Parameters: None Returns: A descriptive String. class Static method XX_YourName_Lab4 where XX is your tutorial class (e.g. T1, T2, etc.) main Prompts user to enter information of a triangle. Displays the triangle (appropriate information) and the area. Allows user to repeat until he decides to quit.
Expert Answer:
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
Briefly describe ASCII and Unicode and draw attention to any relationship between them. [3 marks] (b) Briefly explain what a Reader is in the context of reading characters from data. [3 marks] A...
-
A company supplies concrete slabs for paving. The slabs are made to order in batches of 20; all slabs in a batch are identical. Customers can order from a small range of standard sizes and colours....
-
In Exercises 7683, use a graphing utility to graph the function. Use the graph to determine whether the function has an inverse that is a function (that is, whether the function is one-to-one). f(x)...
-
Refer to Figure 3.37 used in Exercise 7 and construct a bar chart to depict the same data in a way that is fair and objective. Figure 3.37 Daily Oil Consumption (millions of barrels 20.0 5.4 United...
-
Based on the following information, calculate the expected return and standard deviation: State of Probability of Rate of Return Economy State of Economy if State Occurs...
-
Listed below are a number of audit procedures that are applied to supporting documentation together with an indication of the purpose of the procedure: 1. A sales order is examined for evidence of a...
-
Solitaire Machinery is a Swiss multinational manufacturing company. Currently, Solitaires financial planners are considering undertaking a 1-year project in the United States. The projects expected...
-
You must include source reference citations in-text and a reference list of complete citations, in support of your essay. Failure to include references will result in loss of points. FACTS: Kadie,...
-
Required Determine Taxable Income and Part I Federal Tax Payable for the Sebago Shop Corp. for the year ending December 31, 2021. First, find the taxable income for Sebago Shop Corp. for the year...
-
A new company issues $30 Million Dollars of 12-year bonds bearing a 9.5% Coupon. If the market demands a 7.0% rate of return for the risk it believes it is taking, how much will the company receive...
-
The Shirt Shop had the following transactions for T-shirts for Year 1, its first year of operations Jan. 20 Apr. 21 Purchased Purchased 330 units $7 $2,310 150 units 58 1,200 July 25 Purchased 240...
-
Nadia flies to Fiji to bask in the sun at the beach. Whenshe gets to the beach she puts on sunscreen and at the end of theday leaves with a dark tan. 1) Describe how has her skin color changed ? 2)...
-
March 5 March 9 March 18. March 25 March 29 Sales Purchase Purchase Sales Totals Activities Beginning inventory Purchase Warnerwoods Company uses a perpetual inventory system. It entered into the...
-
I must answer questions regarding the movie my cousin Vinny and answer some of these questions. Name the movie and the year the movie was produced. What is the main plot of the movie? Briefly state...
-
Answer the following questions: 1. Describe warranty requirements and explain the three common types of warranties. 2.If your purchase does not come with a written warranty, is it still covered by an...
-
1) The government decided to reduce taxes on fast-food to increase revenue. The government assumes that fast-food products have a) An inelastic demand b) An elastic demand c) A demand curve that is...
-
Examine resource rental pattern on following characteristics: a. Simplicity b. Generality c. Reusability d. Completeness e. Stability f. Visual and graphical model g. Testability
-
Why is it required to have two different patterns for account and entry?
-
Draw a class diagram for account with entry pattern.
Study smarter with the SolutionInn App