import java.util.Scanner; /** * Trig class to perform trig function for our Graphing Calculator * (sin, cos, tan, inverses, degree to radian) * Lauren Green * 10/19/18 */ public class Trig { int input = 0; double answer; public Trig() { boolean validInput = false; while(!validInput) { //Get input of type of function Scanner in1 = new Scanner(System.in); System.out.println("Which trignometric function would you like to run? \n sin, cos, tan, arcsin, arccos, arctan"); String operation = in1.nextLine(); operation = operation.toLowerCase(); //Get input of number Scanner in2 = new Scanner(System.in); System.out.println("What number would you like to find the " + operation + " of?"); int input = in2.nextInt(); //Do the math depending on the input. if (operation.equals("sin")) { answer = Math.sin(input); System.out.println(answer); validInput = true; } else if (operation.equals("cos")) { answer = Math.cos(input); System.out.println(answer); validInput = true; } else if (operation.equals("tan")) { answer = Math.tan(input); System.out.println(answer); validInput = true; } else if (operation.equals("arcsin")) { answer = Math.asin(input); System.out.println(answer); validInput = true; } else if (operation.equals("arccos")) { answer = Math.acos(input); System.out.println(answer); validInput = true; } else if (operation.equals("arctan")) { answer = Math.atan(input); System.out.println(answer); validInput = true; } else { System.out.println("Error, try again \n"); } } //Ask if they would like to convert. System.out.println("Would you like to convert your answer from radian to degrees? Y or N"); Scanner in3 = new Scanner(System.in); String response = in3.nextLine(); response = response.toLowerCase(); if (response.equals("y")) { toDegrees(answer); } else { System.out.println("Have a nice day!"); //Insert Return to Main Menu } } public void toDegrees(double answer) { double conversion = Math.toDegrees(answer); System.out.println(conversion); //Insert Return to Main Menu } }