Question: Create a new project, and then add a class named Triangle. The Triangle class will need 6 instance variables to represent the x,y locations of
Create a new project, and then add a class named Triangle. The Triangle class will need 6 instance variables to represent the x,y locations of the three corners for the triangle. These values should be doubles. Do not use any other instance variables beyond these 6 to store the three corners of our triangle. (As part of the lab you will create accessor methods for side length, and there will also be an accessor method for perimeter. The perimeter method can simply call each of the 3 side length methods and add the values together to calculate the perimeter. A method can call another method in the same class, you will need this concept for this lab!) Add a class named TriangleRunner. This is your tester. You will need a main method in this class. You should create tests for all of the methods in your Triangle class in the TriangleRunner main method. (Create a Triangle object, call its methods, and print actual values. You do NOT need to print expected values this time because a user could enter any points they wish for a Triangle, so your program will not know what the expected values should be). Task01: Problem P4.3 from the book. In this project, you will perform calculations with triangles. A triangle is defined by the x and y coordinates of its three corner points. Your job is to compute the following properties of a given triangle: the lengths of all sides the angles at all corners
the perimeter the area Implement a Triangle class with appropriate methods (method names will be listed for you below). Supply a program that prompts a user for the corner point coordinates and produces a nicely formatted table of the triangle properties. (Also be sure to print expected results). Here is a list of methods you must include (and name exactly the same) in your Triangle class: Constructor: public Triangle() must accept 6 doubles, in the order x1, y1, x2, y2, x3, y3. Accessors: getSide1Length(), getSide2Length(), getSide3Length() getAngle1(), getAngle2(), getAngle3() getPerimeter(), getArea() You may wish to visit this site to brush up on your trigonometry / geometry. http://www.mathsisfun.com/algebra/trig-solving-triangles.html Here is an interaction with the program including output: Enter the x,y coordinates of three points in this order x1,y1,x2,y2,x3,y3: 0 0 1 0 0 1 Side 1 length: 1.000 Side 2 length: 1.000 Side 3 length: 1.414 Angle 1: 90.000 Angle 2: 45.000 Angle 3: 45.000 The perimeter of the triangle is 3.414 The area of the triangle is 0.500 The output above is for a right triangle, and thus you can see one of the angles is 90 degrees. Make sure to convert your angle measurement to degrees. (There is a Math method to do this). You do not have to do your calculations in the same order as my output, as long as you have all the values. (i.e. you might list side 1 length as 1.414 and side 2,3 length as 1.000, and this is acceptable). You MUST use printf to make your output neat. (Limit the number of decimal places, and line up the output in neat columns). Here is another example:
Task02: Get a screen capture of your final output, which should show output for Task01.
TriangleRunner text:
import java.util.Scanner; public class TriangleRunner { public static void main(String[] args) { //prompt and scan in the values for the three corners of your triangle //create a new triangle with the values the user entered //print out the results making method calls //you do not have to print expected results, only actual results } }
Triangle Text:
public class Triangle { //declare appropriate instance variables here //to hold the coordinates of the 3 corners of the triangle public Triangle(double x1, double y1, double x2, double y2, double x3, double y3) { //fill in this constructor } public double getSide1Length() { //fill in this method //return the proper value here return 0; } public double getSide2Length() { //fill in this method //return calculated value here return 0; } public double getSide3Length() { //fill in this method //return calculated value here return 0; } //see the lab document for a link to a website //with instructions on how to calculate angles of //a triangle public double getAngle1() { //fill in this method //return calculated value here return 0; } public double getAngle2() { //fill in this method //return calculated value here return 0; } public double getAngle3() { //fill in this method //return calculated value here
return 0; } public double getPerimeter() { //fill in this method //return calculated value here return 0; } //see lab instructions for how to calculate this //there is a link to a website public double getArea() { //fill in this method //return calculated value here return 0; } }
Triangle:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
