Assignment 2 – Right Triangle

In a right triangle, the square of the length of the longest side is equal to the sum of

the squares of the lengths of the other two sides. Write and test a Visual Basic

program to complete the following project, determining whether a given triangle is

“right” or not based on the lengths of its sides.

GUI

Place three textboxes on a form, along with at least one label for the user to enter

the lengths of the sides of a triangle

Place a label beneath the three textboxes, centered horizontally on the form. Leave

the label’s text property empty.

Place a button beneath all the textboxes with the text “Is this a right triangle?”.

Size the button to display all the text on one line.

Place a single button at the bottom of the form, with the text “I don’t know yet”.

Code

Declare variables to hold the lengths of the three sides of a triangle. All should be

doubles.

Create an event handler for the click event in the first button. All the following

activities must take place within this event handler.

Reset the last button to its default appearance and text.

Input three values representing the lengths of three sides of a triangle in inches

from the three textboxes. Validate each of these values. If any input value is less

than 0.1 inches, clear the corresponding textbox and set the text in the label to

indicate that the offending value is too small.

Identify the longest side as the hypotenuse. Do no assume or require the user to

identify the longest side. Do this in code.

Calculate the expected length of the hypotenuse based on the lengths of the 2

shorter sides.

Compare the expected length of the hypotenuse to the length input by the user.

If the two lengths are the same, declare the triangle to be “Right”, display the

word “Right” in the last button and set its background color to green. Otherwise,

declare the triangle to be “Not Right”, display the words “Not Right” in the last

button and set its background color to red.