import java.io.*;
public class Trig {
double angle;
double sine;
double cosine;
double tangent;
double cotangent;
double secant;
double cosecant;
public Trig(double angle) {
this.angle = angle;
sine = sin();
cosine = cos();
tangent = tan();
cotangent = cot();
secant = sec();
cosecant = csc();
}
public static double equiv(double angle) {
return(angle*3.1415926535/180);
}
private int factorial(int n) {
int product = 1;
for (int counter=2;counter <= n;counter++)
product *= counter;
return(product);
}
public double sin() {
double sum = Trig.equiv(angle);
int counter = 3;
double nextTerm = Math.pow(Trig.equiv(angle),counter);
nextTerm /= factorial(counter);
while (nextTerm >= 0.00005) {
if (counter % 4 == 1)
sum += nextTerm;
else
sum -= nextTerm;
counter += 2;
nextTerm = Math.pow(Trig.equiv(angle),counter);
nextTerm /= factorial(counter);
}
return(sum);
}
public double cos() {
double sum = 1;
int counter = 2;
double nextTerm = Math.pow(Trig.equiv(angle),counter);
nextTerm /= factorial(counter);
while (nextTerm >= 0.00005) {
if (counter % 4 == 0)
sum += nextTerm;
else
sum -= nextTerm;
counter += 2;
nextTerm = Math.pow(Trig.equiv(angle),counter);
nextTerm /= factorial(counter);
}
return(sum);
}
public double tan() {
return(sin()/cos());
}
public double cot() {
return(cos()/sin());
}
public double sec() {
return(1/cos());
}
public double csc() {
return(1/sin());
}
public String toString() {
String outputLine = "\n";
outputLine += "Original Angle:" + "\t\t" + angle + "\n";
outputLine += "Radian Equivalent:" + "\t" + Trig.equiv(angle) + "\n";
outputLine += "Sine:" + "\t\t\t" + sine + "\n";
outputLine += "Cosine:" + "\t\t\t" + cosine + "\n";
outputLine += "Tangent:" + "\t\t" + tangent + "\n";
outputLine += "Cotangent:" + "\t\t" + cotangent + "\n";
outputLine += "Secant:" + "\t\t\t" + secant + "\n";
outputLine += "Cosecant:" + "\t\t" + cosecant + "\n";
return(outputLine);
}
public static void main(String[] args) throws IOException {
InputStreamReader stream = new InputStreamReader(System.in);
BufferedReader keyboard = new BufferedReader(stream);
System.out.println("Please enter your angle in degrees.");
double angle = new Double(keyboard.readLine()).doubleValue();
System.out.println("\n" + "Here is the information I've computed about your angle.");
Trig myTrig = new Trig(angle);
System.out.println(myTrig);
}
}