Question
You will be completing two tasks: 1) Find the area of a triangle given three sides. Find the surface area of a cylinder given the
You will be completing two tasks:
1) Find the area of a triangle given three sides.
Find the surface area of a cylinder given the radius and height of the cylinder.
Given the starter file (MyAreaCalculations.java), finish the program by writing triangleArea and cylinderSurfaceArea methods based on the given method documentation.
Write a method called triangleArea that accepts the three side lengths of a triangle as parameters and returns the area of a triangle with those side lengths. To compute the area, use Heron's formula, which states that the area of a triangle whose three sides have lengths a, b, and c, is the following. The formula is based on the computed value s, a length equal to half the perimeter of the triangle:
area=s(sa)(sb)(sc)area=s(sa)(sb)(sc) s=a+b+c2s=a+b+c2
Write a method called cylinderSurfaceArea that accepts a radius and height as parameters and returns the surface area of a cylinder with those dimensions. The formula for the surface area of a cylinder with radius r and height h is the following:
surfaceArea=2r2+2rh
THIS IS THE FILE: /** * Methods in class calculate area for various shapes. * * @author */ public class MyAreaCalculations { /** * The method that is executed when the program is run * * @param args command line arguments */ public static void main(String[] args) { System.out.println(triangleArea(8, 5.2, 7.1));// EXPECTED OUTPUT: // 18.151176098258745 System.out.println(triangleArea(3.0, 4.0, 5));// EXPECTED OUTPUT: 6.0 System.out.println(cylinderSurfaceArea(3.0, 4.5)); // EXPECTED OUTPUT: // 141.3716694115407 System.out.println(cylinderSurfaceArea(5, 5)); // EXPECTED OUTPUT: // 314.1592653589793 } /** * Returns the area of a triangle with given side lengths * * @param sideA first side of triangle * @param sideB second side of triangle * @param sideC third side of triangle * @return */ public static double triangleArea(double sideA, double sideB, double sideC) { // TODO: Complete method. HINT: Use Math class methods } /** * Returns the surface area of a cylinder with the given radius and height * * @param radius radius of cylinder * @param height height of cylinder * @return surface area of cylinder with radius and height */ public static double cylinderSurfaceArea(double radius, double height) { // TODO: Complete method. HINT: Use Math class methods and constant } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started