next up previous
Up: APS105 Home

APS 105 - Computer Fundamentals

Lab #2: Debugging, Loops and Conditionals

Fall 2000

You must submit this lab by 11:59pm Wednesday, September 27.


Objective
In this lab you will be writing a program that uses both decision making and looping techniques. The program will compute the properties of triangles based on the lengths, which are entered by the user.



The Problem
Triangles can be classified in a number of ways by considering the relative sizes of either their sides or their angles. Using side classifications, a triangle is equilateral if all sides are equal; it is isosceles if exactly two sides are equal; it is scalene if no sides are equal. Using angle classifications, a triangle is a right triangle if its largest angle is a right angle; it is obtuse if its largest angle is greater than a right angle; it is acute if its largest angle is less than a right angle. If the sides of a triangle are known, Pythagoras' Theorem can be used to classify the triangle as right, obtuse, or acute.

         Write a program that will read an arbitrary number of sets of three integer values. The program should prompt the user for sets of numbers and process them until the user submits the numbers 0 0 0. For each set of three numbers, the program should first print the values read. It should then decide whether or not the three numbers could represent the lengths of the sides of a triangle. If the numbers could not represent the lengths of sides of a triangle, an appropriate message should be printed. If they could, then the program should determine and state into which of the above classes the triangle would be placed.



Sample Results
If the user provided input of
3 5 4
5 2 5
-7 1 2
0 0 0
then the program should produce output something like the following:
Please provide three side lengths, or 0 0 0 to terminate.
3 5 4 A triangle can be formed. It is scalene and right.
Please provide three side lengths, or 0 0 0 to terminate.
5 2 5 A triangle can be formed. It is isosceles and acute.
Please provide three side lengths, or 0 0 0 to terminate.
-7 1 2 A triangle cannot be formed.
Please provide three side lengths, or 0 0 0 to terminate.
0 0 0 Program was terminated by user.

Note: Due to the way Stdin.getInt() (or Stdin.getDouble()) work, the triplet 3 5 4 must be provided by the user on 3 separate lines. We wrote the input as triplets above so it is easier for you to follow while reading this handout.

Note: Your program can use either integer lengths or floating-point lengths, the choice is yours. However, to aid in marking, it would be appreciated if you used integer values.



Suggestions
You may find it useful to solve the problem in stages. A possible sequence of steps could be to first write a program that requests three integer values and prints them, looping until the user submits 0 0 0. Once this is working, modify the program so that, for each set of values, the program determines whether or not they could represent the lengths of sides of a triangle. Next, have the program classify the triangles by sides. Finally, have the program classify the triangles by angles.

Don't forget to electronically submit your solution:

p2.ecf% submitaps105f 2 TriangleProperties.java Stdin.java

next up previous
Up: APS105 Home
Guy G. Lemieux
2000-09-23