Question

Problem a (PA4a.java) Write a program to evaluate the area of a triangle given the lengths of its sides using Herons Formula. Here is an outline: Get the three side lengths from the user (which might have decimal values): a, b, c. Check to ensure that the sides are valid for a triangle. Importantly, the sum of the lengths of any two sides must be larger than the length of the third side (you must check all three sides this way). Calculate the semiperimeter (s): 1. 2. 3. a+b+c 2 4. Calculate the area: area = V s(s-a) (s-b)(s-c) You must format the output to have two decimal places (even if they are both o), and round if necessary. For example: Enter the length of side a: 3 Enter the length of side b: 4 Enter the length of side c: 5 The area is 6.00 http://en.wikipedia org/wiki/Heron%27.formula
media%2F877%2F87733a0c-6d11-4bdc-ad38-3d
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student,

here is the complete Java code which perform the required task.

Please note that the below code has been compiled using javac compiler in ubuntu 16.04 system.

-------------------------------------------------------------------------------------------------------------------------------------

Program:

-------------------------------------------------------------------------------------------------------------------------------------

//import the required packages

import java.util.Scanner;

import java.lang.*;

//public class

public class Area
{

    //main class

    public static void main(String[] args)
    {

        //scanning input

        Scanner input = new Scanner(System.in);

        System.out.printf("Enter the length of side a: ");

        int a = input.nextInt();

        System.out.printf("Enter the length of side b: ");

        int b = input.nextInt();

        System.out.printf("Enter the length of side c: ");

        int c = input.nextInt();

        //calculating the seme-perimeter

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

        //calculating the area

        double A = Math.sqrt(s * (s - a) * (s - b) * (s - c));

        //display the area

System.out.println("The area is: "+A);

    }

}//end of the program


------------------------------------------------------------------------------------------------------------------------------------------

here i have attached the output of the program as a screen shot..

Output:

-----------------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------------------

Kindly Check and Verify Thanks...!!!

Add a comment
Know the answer?
Add Answer to:
Problem a (PA4a.java) Write a program to evaluate the area of a triangle given the lengths...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Please - Design and implement a class Triangle. A constructor should accept the lengths of...

    Java Please - Design and implement a class Triangle. A constructor should accept the lengths of a triangle’s 3 sides (as integers) and verify that the sum of any 2 sides is greater than the 3rd(i.e., that the 3 sides satisfy the triangle inequality). The constructor should mark the triangle as valid or invalid; do not throw an exception. Provide get and set methods for the 3 sides, and recheck for validity in the set methods. Provide a toString method...

  • 10. Use Heron's formula to calculate the area of a triangle. In below formula, a, b,...

    10. Use Heron's formula to calculate the area of a triangle. In below formula, a, b, and c are the length of 3 sides of a triangle: s (a+b+c]/2 A Vs(s-a) (s-b) (s- e) Write a program to calculate area of triangle. Input a, b, e from console and display area.

  • Please help c++ Heron's Formula for the area of a triangle with sides a, b and...

    Please help c++ Heron's Formula for the area of a triangle with sides a, b and c is given by the formula: area = S(S-a) (S-b) (S-c) where s = (a+b+c)/2 Write a complete program which in main asks the user for the sides a, b and c of a triangle. Use variables of type double. Pass a, b and c to a function called area. In area calculate s defining s as a local variable. Then use s, a,...

  • Must be java code Project 2b: CalculatePerimeter You are to write code for the application CalculatePerimeter where the computer calculates and displays the perimeter of a triangle, provided the three...

    Must be java code Project 2b: CalculatePerimeter You are to write code for the application CalculatePerimeter where the computer calculates and displays the perimeter of a triangle, provided the three double values entered from keyboard input represent a triangle. If they don't, the computer should display the fact that (at least, in the case of non-positive input) one of the values does not form a valid triangle What makes a valid triangle? All sides must be positive and the sum...

  • The "for more practice part" using matlab If the lengths of two sides of a triangle...

    The "for more practice part" using matlab If the lengths of two sides of a triangle and the angle between them are known, the length of the third side can be calculated. Given the lengths of two sides (b and c) of a triangle, and the angle between them alpha in degrees, the third side a is calculated as follows a^2 = b^2 + c^2 - 2b c cos(alpha) White a script thirdside that will prompt the user and read...

  • 2. Write a program that prompts a user to enter the lengths of sides and angles...

    2. Write a program that prompts a user to enter the lengths of sides and angles for the two triangles described below. The program should calculate the length of the side of the triangle indicated below. Print the two answers to 3 decimal places onto the console screen Triangle 1 Read in the value of the angle, alpha, and the length, a, of the side indicated in the picture below. Calculate the length of the hypotenuse, c, of this right...

  • In Java, write a class for a Triangle Object that contains, Private instance variables: - three...

    In Java, write a class for a Triangle Object that contains, Private instance variables: - three doubles: a,b,c, representing the three sides of the Triangle - constructor with three double as args, which are put into three instances variables Public Instance Methods: - getPerimeter: computes the perimeter of the triangle(the sum of the three sides), returns a double - getArea: computes the area of the triangle using Heron's formula: Area = (s*(s-a)*(s-b)*(s-c))^0.5, where s = 0.5*(the triangle's perimeter), returns a...

  • 18. The area A of a of a triangle with sides of lengths a and b...

    18. The area A of a of a triangle with sides of lengths a and b and with included angle is given by the formula: A=0 A= Rp2 A= √3(s - a)(sb) A=r0 A = sab sin() Question 18 of 29

  • Write a program to compute the area of a triangle using side-angle-side method and reports the...

    Write a program to compute the area of a triangle using side-angle-side method and reports the area of that triangle (rounded to 2 decimal places). Side-angle-side formula: ???? = 1/ 2 ?? sin(?), where a and b are two sides of the triangle, and C is the included angle. Your program must meet the following criteria to receive full marks: • Randomly generate two values between 5 and 10 (inclusive) for two sides a and b of the triangle, respectively....

  • 3. Write a program to calculate the area of a triangle. Your program will take the...

    3. Write a program to calculate the area of a triangle. Your program will take the length of two sides and the included angle (in degrees), then prints the area based on the following formula. A = 1/2 ab sin C

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT