Assignment 2 Specifications Due: 20 September 2018-class time Assignment: Write
ID: 3746887 • Letter: A
Question
Assignment 2 Specifications Due: 20 September 2018-class time Assignment: Write algorithm() and program(s) to display certain properties of a given triangle refer to P4.3 on page 172 in the text for the basies Output: Output will include all three Points, the lengths of all three sides, the three angles at the corners, the perimeter and the area of the triangle, and whether the triangle is Equilateral or Right-angled or neither al1 in a nicely formatted layout, as directed. Values displayed will be labeled and designated in the appropriate "units", angles will be displayed in "degreesAll printed values will be rounded and formatted to four decimal-point accuracy, degrees rounded to the nearest degree Input: Program wi11 prompt a user to provide x- and y-coordinates for the three Points of a triangle. User input must be validated. User prompts must clearly indicate how to enter values for each Point (which is: a pair of x- and y- coordinates, separated by a ). A coordinate is a floating-point value and can be positive, negative or zero. Requirements: Use only material covered in the first six chapters - no arrays no exceptions. Style requirements as discussed in class expected. Eticiency should always be considered. Round only for output. Choose the most appropriate loop/decision structures and variable types. No graphics Provide a Triangle class with only the appropriate constructor (s), methods and instance variables. Triangle class can only have three instance variables for the three Points. Provide appropriate constants where useful. Provide appropriate accessor methods to compute values not stored in the class instance variables and mutator methods, as well as any required utility Also provide a separate Tester program (main) to prompt the user for the three Points, request the required values from the Triangle class, and then provide the display of the required output. All input/output will be handled by the Tester. See section 4.1 (pages 136-138) for hints on building class and tester programs. Test your programs completely and be sure your Tester tests all methods of your Triangle class! and The links: ttpetowmathaafn .com/.geonetzy/hecons-fohm triangle formulas. The link: may contain some useful tsplww.mathopepref comtocseeson.hm may provide some other triangle insights. Use of the “Point" class is required-Appendix D (AI7-18) in the text- java.awt.geom -along with page 67, may prove useful for Points. Submission: Your program must be able to compile and execute on FIU SCIS, using the "java" compiler. Test it there before you submit Name your primary source code file: TriangleTester.java and your class source code file: Triangle.javaOnly two source code files Refer to the Moodle documents: How to Develop a Simple Java Progran and "Style Guide“ for details on expected program format and documentation. Review both documents carefully! Note the class source code file will use the class heading documentation, the tester (main) source code file will use the program heading documentation Algorithm (pseudocode) should be submitted for each progran and in separate text files and included with the Moodle posting and class submission Print out a copy of your primary source code, class source code and pseudocode and submit in class signed, stapled and collated in the specified sequence: primary source code (w/main) file, class source code file and then the pseudocode text files Post azip file with all source code (-java) and text files -on the Moodle web site. Do not include any extraneous (IDE) files in the Moodle submission Program documentation must include the required signed disclainer (cosment) in the heading no grade will be assigned to prograns that onit the disclaimer orExplanation / Answer
/**
* Auto Generated Java Class.
*/
import java.util.*;
import static java.lang.Math.*;
class Triangle
{
// Method to compute Distance between two points
double computeDistance (double x1, double y1, double x2, double y2)
{
return Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}
//Method to compute angle between two sides
double computeAngle (double side1, double side2, double sideOpposite)
{
return radianToDegrees ( Math.acos(((side2 * side2) + (sideOpposite * sideOpposite) - (side1 * side1)) / (2 * side2 * sideOpposite)) );
}
// Helper function to convert radian to degrees
double radianToDegrees (double radians)
{
return Math.round( 180 * radians / Math.PI );
}
//Method to compute perimeter
double computePerimeter(double side1, double side2, double side3)
{
return (side1 + side2 + side3);
}
//Method to compute area
double computeArea (double side1, double side2, double side3)
{
double s4 = 0.5*(side1+side2+side3);
return Math.sqrt(s4 * (s4 - side1) * (s4 - side2) * (s4 - side3));
}
// Method to check if a triangle is equilateral
boolean isEquilateral(double side1, double side2, double side3)
{
return (side1 == side2 && side2 == side3 && side3 == side1);
}
//Method to check if a triangle is right angled
boolean isRight(double side1, double side2, double side3)
{
double m1 = Math.round( (side2*side2) + (side3*side3) );
double m2 = Math.round( (side3*side3) + (side1*side1) );
double m3 = Math.round( (side2*side2) + (side1*side1) );
if ( Math.round(side1*side2) == m1 || Math.round(side2*side2) == m2 || Math.round(side3*side3) == m3 )
return true;
else
return false;
}
}
// Triangle Tester.java code
/**
* Auto Generated Java Class.
*/
import java.util.Scanner;
public class TraingleTester {
public static void main(String [] args )
{
Scanner console = new Scanner(System.in);
System.out.println ("Enter First set of co-ordinates");
double x1 = console.nextDouble();
double y1 = console.nextDouble();
System.out.println ("Enter second set of co-ordinates");
double x2 = console.nextDouble();
double y2 = console.nextDouble();
System.out.println ("Enter third set of co-ordinates");
double x3 = console.nextDouble();
double y3 = console.nextDouble();
Triangle tri = new Triangle();
double side1 = tri.computeDistance(x1,y1,x2,y2);
double side2 = tri.computeDistance(x2,y2,x3,y3);
double side3 = tri.computeDistance(x1,y1,x3,y3);
double angle1 = tri.computeAngle(side1, side2, side3);
double angle2 = tri.computeAngle(side2, side3, side1);
double angle3 = tri.computeAngle(side1, side3, side2);
double area = tri.computeArea(side1, side2, side3);
double perimeter = tri.computePerimeter(side1, side2, side3);
String is_equilateral = "False";
if ( tri.isEquilateral(side1, side2, side3) )
{
is_equilateral = "True";
}
String is_right_angled = "False";
if ( tri.isRight(side1, side2, side3) )
{
is_right_angled = "True";
}
System.out.println("Expected: (10.0, 20.0)") ;
System.out.println("Point 1 Coordinates: (" + x1 + "," + y1 + ")");
System.out.println("Point 2 Coordinates: (" + x2 + "," + y2 + ")");
System.out.println("Point 3 Coordinates: (" + x3 + "," + y3 + ")");
System.out.println("Side 1 length: " + side1 + " units");
System.out.println("Side 2 length: " + side2 + " units");
System.out.println("Side 3 length: " + side3 + " units");
System.out.println("Angle 1:" + angle1 + " degrees");
System.out.println("Angle 2:" + angle2 + " degrees");
System.out.println("Angle 3:" + angle3 + " degrees");
System.out.println("The perimeter of the triangle is " + perimeter + " units");
System.out.println("The area of the triangle is " + area + " units");
System.out.println("The triangle is equilateral?: " + is_equilateral );
System.out.println("The triangle is Right-angled?: " + is_right_angled);
}
}