Learning objectives Implementing a Class Writing a Tester Pr

Learning objectives Implementing a Class Writing a Tester Program More on Using Decision Statements, More on Using the Standard Java Math Library Methods Definition 1. The distance between two points is the length of the path connecting them. In the plane, the Euclidean distance between between points P (ri, yi) and Pi 3(ri, yi), denoted F Pi, is given by the Pythagorean theorem. yi) (1) Definition 2. A triangle is a three-sided polygon formed by connecting three non-collinear points in a plane with line segments. Definition 3. Three or more points are said to be collinear if they lie in the same line. Collinear points cannot form the vertices (corners) of a (a1, 1), P2 (a2, y2) and P triangle. \'Three points, P are collinear if they satisfy the equation below r2) (y1 (2) Definition 4. A triangle is isosceles when (at least) two sides are equal. Definition 5. A triangle is equilateral when all sides equal. Definition 6. A triangle is scalene when no two sides equal. Definition 7. A triangle is right if m si s?, where s s2, are its shorter sides and m is the longest side

Solution

import java.util.Scanner;

public class TriangleDemo {

    public static void main(String[] args){

        Scanner input = new Scanner(System.in);

        System.out.print(\"Enter the length of the three sides of your triangle: \");

        double a = input.nextDouble();

        double b = input.nextDouble();

        double c = input.nextDouble();

        System.out.println(\"The lengths of the sides of your triangle are: \" + \'\ \' + a + \'\ \'+ b + \'\ \' + c);

        System.out.println(\"The are of your triangle according to Heron\'s Formula is: \" + getArea(a,b,c));

         

    }

    public static double getArea(double a, double b, double c) {

        double s = (a + b + c)/2;

        double x = ((s) * (s-a) * (s-B)/> * (s-c));

        double area = Math.sqrt(x);

        return area;

    }

}

import java.util.Scanner;

import java.text.*;

public class TriangleTestDemo

{

    int a, b, c;

     

    MyTriangle()

     {

        this.a=0;

        this.b=0;

        this.c=0;

     }

     TriangleTestDemo (int a, int b, int c)

     {

        this.a=a;

        this.b=b;

        this.c=c;

     }

   public static void main(String[] args)

   {

        Scanner input = new Scanner(System.in);

           boolean valid = true;

           double side1, side2, side3, area, s;

   

        System.out.print(\"Please enter side1: \");

        side1 = input.nextDouble();

       

        System.out.print(\"Please enter side2: \");

        side2 = input.nextDouble();

             

        System.out.print(\"Please enter side3: \");

        side3 = input.nextDouble();

        valid = isValid(side1, side2, side3);

         

         TriangleTestDemo obj = new TriangleTestDemo();  

        if(valid)

        {

          double x= obj.area(side1, side2, side3);

             

         

        System.out.print(\"The area of the triangle is: \" + x);

        }

        else             

        System.out.println(\"The input is not valid\");

     }

     public static boolean isValid(double side1, double side2, double side3)

     {

          return(((side1 + side2) >side3) && ((side2 + side3) > side1) && ((side3 + side1) >side2));

     }

     public static double area(double side1, double side2, double side3)

     {

          double s = (side1 + side2 + side3)/2;

          double area = Math.sqrt(s * (s - side1) * (s - side3)*(s-side2));

          return area;

     }

     

      

      

     

      

}

import java.util.Scanner;

 Learning objectives Implementing a Class Writing a Tester Program More on Using Decision Statements, More on Using the Standard Java Math Library Methods Defin
 Learning objectives Implementing a Class Writing a Tester Program More on Using Decision Statements, More on Using the Standard Java Math Library Methods Defin
 Learning objectives Implementing a Class Writing a Tester Program More on Using Decision Statements, More on Using the Standard Java Math Library Methods Defin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site