The Question

The sum of the first 3 terms of the Taylor series expansion of cos (x) is given by

1 - (1/2)x*x + (1/24)x*x*x*x

Use the Fraction class defined in type.lib to evaluate the above expression. Your program should read in 'x' as a pair of integers that define x as a fraction a/b and then use the Fraction class to evaluate this approximation to cos(x) as a fraction. Your program should prompt the user for the input 'x' and output the approximation to cos(x). Call your program Q1.java

The output should conform to that in the sample runs of a correct program shown below. Note that, in these sample runs, the % sign is not part of the program output. User input is shown on the same line as the prompt.

Sample Runs

% java Q1
Enter the numerator and denominator for x ... 0 1
cos(0/1) is approximately 1/1
%
% java Q1
Enter the numerator and denominator for x ... 1 1
cos(1/1) is approximately 13/24
%

Useful APIs

Here (again) are the common APIs that you may access:

Java 1.5 API
Type API

Submitting Your Work

Here is the command to submit your work (further details regarding the submit command can also be obtained by typing man submit
Once again, you are encouraged to submit regularly. Newer submissions overwrite older ones.

submit 1020 midtermW7 Q1.java