Project_1_Report

advertisement
Assignment Description:
Each team member must develop a program (using Java, C, or C++) that classifies triangles according to
the following specification:
“A program reads three numbers. The three numbers represent the lengths of the sides of a triangle.
The program prints a message that states whether the triangle is scalene, isosceles, or equilateral, and
whether it is a right triangle as well.”
The program should be able to pass a basic sanity test.
Once completed, a copy of the program should be given to teammates.
Author(s): William Rozzo
Summary:
After reading the assignment description for the first time I thought that it might take me 30 minutes to
whip up a simple program. Once I started programming however, I realized that I needed to brush up
slightly on my trig skills. I was all set once I remembered the law of cosines. I needed this formula since
according to the assignment description, the program will only know side lengths. Without at least one
angle I had to resort to the law of cosines to generate all three triangle angles. Luckily I chose to use Java
for this assignment. Java has a bunch of built in math functions as well simple exception handling, just in
case users decide to enter invalid information. One other thing I did not take in to account at the get go
was the fact that given three arbitrary lengths, they don't always make a triangle. I made sure that the
program took this fact in to consideration as well.
Honor pledge
I, William Rozzo, pledge on my honor that I have not given or received any unauthorized assistance on
this assignment/examination. I further pledge that I have not copied any material from a book, article,
the Internet or any other source except where I have expressly cited the source.
Detailed results:
The Java programming language was used for this assignment. Two source code files were developed;
Triangle.java and TriangleEvaluator.java.
Triangle.java: This class represents the "Triangle" object. For the purposes of this assignment, the
Triangle object is made up of sides, angles, and a name. The triangle object is responsible for the angle
and triangle name calculations.
TriangleEvaluator.java: This class is the main driver class. It is responsible for parsing the users inputs be
it from the command line or from the prompt. It then takes the received input and creates the triangle
object. Once the triangle is created, information about the triangle is queried for and displayed to the
user.
Assumptions:
All triangles have three sides. The user might not always enter three sides that make a valid triangle. The
user is only interested in one pass through the program (program does not restart unless re executed, all
previous information/calculations are lost). Lastly, since there may be some rounding error, if an angle is
calculated to be between 90.0 and 90.5 it will be considered a right angle.
Sanity test:
Test case 1: Generate an Equilateral triangle
Test case 2: Generate a Scalene triangle
Test case 3: Generate an Isosceles triangle
Test case 4: Generate a Right Scalene
Test case 5: Generate a Right Isosceles
Download