Question: Write a program to allow the user to create an triangle and calculate the area. The program will prompt the user to enter the


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.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
