Write a program to implement triangle questions in java.
Tags: java, javahomeworkhelp, programmingassignmenthelp, javaassignmenthelp
Published: 2023-03-07 07:26:59


Requirements and Specifications

Write a program that inputs 3 numbers, and determines if these numbers are sides of a triangle. if a value <=0 is entered ignore that data, and exit the program.
To be a triangle. the sum of any 2 sides of a triangle must be greater than the 3rd side.  all the numbers input will be integers.


http://www.mathwarehouse.com/geometry/triangles/triangle-inequality-theorem-rule-explained.php


if it is a valid triangle, determine the area(Herons formula), and perimeter of the triangle(sum of all sides), and if it is scalene(no sides equal), isosceles(2 sides equal), or equilateral(all sides equal)
and if it’s a right triangle (a2 +b2 =c2 –-remember you did not necessarily input the largest side last)
 
Herons formula
http://www.mathopenref.com/heronsformula.html


you must have at least 2 methods in addition to main


you may not use Math.max or Math.min or anything other than what we covered in chapters 1,2,3, 4, 5.
Name your project LastNameProject4 so that mine would be LichtenthalProject4
If you name your file incorrectly, or use anything we did not cover in the specified chapters your grade will be 0
sample runs


```
Source Code


import java.util.Scanner;

public class LastNameProject4 {

    // Entry point of the program
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        // Get the 3 sides
        System.out.print("Enter side 1: ");
        int side1 = in.nextInt();

        System.out.print("Enter side 2: ");
        int side2 = in.nextInt();

        System.out.print("Enter side 3: ");
        int side3 = in.nextInt();

        // Validate the triangle sides
        if (side1 <= 0 || side2 <= 0 || side3 <= 0) {
            System.out.println("Invalid data entered.");
            return;
        }

        // Check if it's a triangle, the sum of two sides should
        // be greater than the other side
        if (side1 + side2 > side3 && side2 + side3 > side1 && side1 + side3 > side2) {
            // Calculate the perimeter
            double perimeter = side1 + side2 + side3;
            System.out.println("Perimeter: " + perimeter);

            // Calculate the area of the triangle
            double semiPerimeter = perimeter / 2.0;
            double area = Math.sqrt(semiPerimeter
                    * (semiPerimeter - side1)
                    * (semiPerimeter - side2)
                    * (semiPerimeter - side3));

            System.out.println("Area: " + area);

            // Check the kind of triangle
            if (side1 != side2 && side2 != side3 && side1 != side3) {
                System.out.println("No sides equal-scalene");
            } else if (side1 == side2 || side1 == side3 || side2 == side3) {
                System.out.println("2 sides equal-isosceles");
            } else if (side1 == side2 && side2 == side3) {
                System.out.println("3 sides equal-equilateral");
            }

            // Check if right triangle
            if (side1 * side1 + side2 * side2 == side3 * side3
                    || side2 * side2 + side3 * side3 == side1 * side1
                    || side3 * side3 + side1 * side1 == side2 * side2) {
                System.out.println("It is a right triangle");
            } else {
                System.out.println("It is not a right triangle");
            }
        } else {
            // Not a triangle
            System.out.println("Not sides of a triangle");
        }
    }
}
```

If you need assistance with such assignment or project visit [Java Homework Help](https://www.programminghomeworkhelp.com/java-assignment/) website