import java.util.*; import java.lang.*; /** * Write a description of class Calculator here. * * @author (your name) * @version (a version number or a date) */ public class MathMethods { private static int displayModeCounter=4; public static Double add(double n1, double n2){ return (n1 + n2); } public static Double subtract(double n1, double n2){ return (n1 - n2); } public static Double multiply(double n1, double n2){ return (n1 * n2); } public static Double divide(double n1, double n2){ return (n1 / n2); } public static Double exponent(double n1, double n2){ return (Math.pow(n1, n2)); } public static Double cosine(double n1){ return (Math.cos(n1)); } public static Double invCosine(double n1){ return (Math.acos(n1)); } public static double squareRoot(double n1) { return (Math.sqrt(n1)); } public static double invert(double n1) { return (n1*-1); } public static double sin(double n1){ return (Math.sin(n1)); } public static double iSin(double n1){ return (Math.asin(n1)); } public static double degToRad(double n1) { return (Math.toRadians(n1)); } public static double radToDeg(double n1) { return (Math.toDegrees(n1)); } public static String fortuneCookie() { Random rand = new Random(); String[] wiseWords = new String[] {"You're a hard worker and you will do great on all the labs!", "Look how much java you learned this week! That's awesome!", "Keep up the good work!" , "You're cushing it!", "You're a coding rockstar!", "Keep coding!"}; int arrIndex = rand.nextInt(6); return wiseWords[arrIndex]; } public static double square(double n1) { return Math.pow(n1, 2); } public static String switchDisplayMode(String mode){ Calculator display = new Calculator(); String answer = ""; switch (mode) { case "binary": answer = "0b " + Integer.toBinaryString((int)display.lastAns); break; case "octal": answer = "0 " + Integer.toOctalString((int)display.lastAns); break; case "decimal": answer = String.valueOf(display.lastAns); break; case "hexadecimal": answer = "0x " + Integer.toHexString((int)display.lastAns); break; } return answer; } public String switchDisplayMode(){ String answer = ""; if (displayModeCounter%4 == 0){ answer = switchDisplayMode("binary"); displayModeCounter++; } else if (displayModeCounter%4 == 1){ answer = switchDisplayMode("octal"); displayModeCounter++; } else if (displayModeCounter%4 == 2) { answer = switchDisplayMode("hexadecimal"); displayModeCounter++; } else { answer = switchDisplayMode("decimal"); displayModeCounter++; } return answer; } public static double randomNumber() { Random rand = new Random(); return rand.nextDouble()*101; } public static void printAns(String printAnswer){ System.out.println("ANSWER: " + printAnswer + "\n \n"); } public static double inverse(double n1) { return 1 / n1; } public static double tangent(double n1) { return Math.tan(n1); } public static double iTan(double n1) { return Math.atan(n1); } public static double state() { Calculator display = new Calculator(); return (display.lastAns); } }