/*Lab 6 for 11th September 2008*/ /* Area of a triangle using Taylor’s series formula for sine : In mathematics, the Taylor series is a representation of a function as an infinite sum of terms. The Taylor series is a representation of sine function is given by sin(x) = x − x^3/3! + x^5/5! - x^7/7! + x^9/9! - .......... where x is in radians. Design the following function: (double) sin (double x): Takes x in radians and returns sin(x). Optional: For implementing the sin function, you have a choice of using the following functions, which would enhance the readability of the code, but decrease the speed of the program: (double) power (double x, int k): Returns xk . (int) factorial (int n): Returns n!. Using the function sin as described above, write a program which, given two sides of a triangle and the angle between them, computes the area of the triangle. You have to give input through terminal with first two values for the two sides of the triangle and the third input for the angle in radian. */ /* given the length of two sides a,b and the angle x between them the area of triangle is 0.5*a*b*sin(x) */ class TriangleArea { public static int factorial(int x) //method for calculating the factorial of given number { int factorial=1; for(int i=1;i<=x;i++) { factorial = factorial*i; } return factorial; } public static double sin (double x) //method for calculating sin value { double sinvalue = 0; for(int i=0;i<=10;i++) { int k = 2*i + 1; sinvalue = sinvalue + Math.pow(-1,i) * Math.pow(x,k)/factorial(k); } return sinvalue; } public static void main(String args[]) // main method takes input from user through command line and calculate the ar { double side1,side2,angle,area; side1 = Double.parseDouble(args[0]); side2 = Double.parseDouble(args[1]); angle = Double.parseDouble(args[2]); area = 0.5 * side1 * side2 * sin(angle); System.out.println("the area of trianle is " + area); } }