# Program Triangle Solution

\$30.00

Category:

## Description

 File Name: H:\CPSC1150\Lab4\Triangle.java Purpose To calculate the perimeter of a triangle by letting the user to enter 3 coordinates by using Pythagoras to solve . Input x-coordinates 1,2 and 3 and y-coordinates 1,2 and 3 Output The perimeter of a triangle

### Program Logic (Pseudocode)

Algorithm Triangle

Start

1. Initialize variables

(a) x-coordinate 1 (input) in int

(b) y-coordinate 1 (input) in int

(c) x-coordinate 2 (input) in int

(d) y-coordinate 2 (input) in int

(e) x-coordinate 3 (input) in int

(f) y-coordinate 3 (input) in int

(g) side 1 (calculation) in double

(h) side 2 (calculation) in double

(i) side 3 (calculation) in double

(f) perimeter (output) in double

1. Allow the user to enter an input for the x and y coordinates

(a) If any of the x or y coordinates are above 40, let the user know and terminate the program

(b) If any of the x or y coordinates are below 0, let the user know and terminate the program

(c) If all 3 x-coordinates are on the same line, let the user know and                                                terminate. Due to it not being a triangle

(d) If all 3 y-coordinates are on the same line, let the user know and

terminate. Due to it not being a triangle

1. Display the perimeter of the triangle

(a) Using Pythagoras = (a2+b2)1/2 to calculate the length of each side

(b) Calculate the perimeter by adding all 3 sides up

(c) Display to the user

1. Ask if the user if he would like to repeat the process

(a) Create a loop with steps 2 and 3, so if the user would like to do another                                    calculation then allow him

(b) Ask the user if he would like to repeat the calculations

1. Terminate

(a) When the user does not want to run the program again

error: Content is protected !!