import java.util.*; import java.text.DecimalFormat; public class MainApplication { public static void main(String[] args) { Scanner input = new Scanner(System.in); CoreFeatures cor = new CoreFeatures(); CustomFeatureDistance cust = new CustomFeatureDistance(); CoreAl cal =new CoreAl(); ScientificAl sci=new ScientificAl(); CustomFeatureTemperature custom= new CustomFeatureTemperature(); double calculationResult = 0; double conversionResult = 0; double mem = 0; //double defaultCalcResult = 0; //System.out.println("Enter a command: "); //consider using boolean to store the first calculation (first numb) while (true) { try { double defaultCalcResult = 0; System.out.println("Enter a command: "); if (calculationResult != 0) { System.out.println(calculationResult); }else { System.out.println(defaultCalcResult); } //User input String command = input.next(); //Makes the current display 0 if (command.equalsIgnoreCase("C")){ calculationResult = defaultCalcResult; System.out.println("Clear!"); //System.out.println("Enter a command: "); } //Turn off calculator if (command.equalsIgnoreCase("exit")){ System.out.print("Thanks for calculating with us!"); break; } //Display Mode if (command.equalsIgnoreCase("DisplayMode")){ String userInput = Console.getStringInput( "Please enter in the desired mode: \n \"Bin\" - for binary \n \"Oct\" - for octal \n \"Dec\" - for deciaml \n \"Hex\" - for hexadeciaml"); if (userInput.equalsIgnoreCase("Bin")){ int userInputBin = Console.getIntegerInput("Please enter the integer value you wish to convert: "); System.out.println("Current value in binary is: " + Integer.toBinaryString(userInputBin)); } if (userInput.equalsIgnoreCase("Oct")){ int userInputBin = Console.getIntegerInput("Please enter the integer value you wish to convert: "); System.out.println("Current value in octal is: " + Integer.toOctalString(userInputBin)); } if (userInput.equalsIgnoreCase("Dec")){ int userInputBin = Console.getIntegerInput("Please enter the integer value you wish to convert: "); DecimalFormat decimalValue = new DecimalFormat("#"); String value = decimalValue.format(userInputBin); System.out.println("Current value in deciaml is: " + value); } if (userInput.equalsIgnoreCase("Hex")){ int userInputBin = Console.getIntegerInput("Please enter the integer value you wish to convert: "); System.out.println("Current value in hexadecimal is: " + Integer.toHexString(userInputBin)); } } //aleeena //double calculationResult=0.0; //while //Scanner input = new Scanner(System.in); /* double defaultCalcResult = 0.0; if (calculationResult != 0.0) { System.out.printf("\nCurrent Value :%.2f",calculationResult); }else { System.out.printf("\nCurrent Value :%.2f",defaultCalcResult); } System.out.print("\nEnter a command: "); String command = input.next(); if (command.equalsIgnoreCase("C")){ calculationResult = defaultCalcResult; System.out.println("Clear!"); } //String command = input.next(); if (command.equalsIgnoreCase("exit")){ System.out.print("Thanks for calculating with us!\n"); break; }*/ if (command.equalsIgnoreCase("square")){ if(calculationResult!=0.00) { double num=calculationResult; calculationResult=cal.square(num); Console.printDouble(calculationResult); } else { double num=Console.getDoubleInput("Enter the number :"); calculationResult=cal.square(num); Console.printDouble(calculationResult); } } if(command.equalsIgnoreCase("squareroot")) { if(calculationResult!=0.00) { double num=calculationResult; calculationResult=cal.squareroot(num); Console.printDouble(calculationResult); } else { double num=Console.getDoubleInput("Enter the number :"); calculationResult=cal.squareroot(num); Console.printDouble(calculationResult); } } if(command.equalsIgnoreCase("exponent")) { if(calculationResult!=0.00) { double power=Console.getDoubleInput("Enter the power"); calculationResult=cal.exponent(calculationResult,power); Console.printDouble(calculationResult); } else { double base=Console.getDoubleInput("Enter the base value"); double power=Console.getDoubleInput("Enter the power"); calculationResult=cal.exponent(base,power); Console.printDouble(calculationResult); } } if(command.equalsIgnoreCase("inverse")) { if(calculationResult!=0.00) { calculationResult=cal.inverse(calculationResult); Console.printDouble(calculationResult); } else { double num=Console.getDoubleInput("Enter the number"); calculationResult=cal.inverse(num); Console.printDouble(calculationResult); } } if(command.equalsIgnoreCase("invert")) { if(calculationResult!=0.00) { calculationResult=cal.invertsign(calculationResult); Console.printDouble(calculationResult); } else { double num=Console.getDoubleInput("Enter the number"); calculationResult=cal.invertsign(num); Console.printDouble(calculationResult); } } if(command.equalsIgnoreCase("sin")) { double number=Console.getDoubleInput("Enter the degree"); double result=sci.sine(number); Console.printDouble(result); calculationResult=0; } if(command.equalsIgnoreCase("cos")) { double number=Console.getDoubleInput("Enter the degree"); double result=sci.cosine(number); Console.printDouble(result); calculationResult=0; } if(command.equalsIgnoreCase("tan")) { double number=Console.getDoubleInput("Enter the degree"); double result=sci.tangent(number); Console.printDouble(result); calculationResult=0; } if(command.equalsIgnoreCase("inversesin")) { String mode=Console.getStringInput ("Type in \"D\" for Degree output\nType in \"R\" to Radians output"); if(mode.equalsIgnoreCase("D")) { double number=Console.getDoubleInput("\nEnter the value :"); calculationResult=sci.inversesinDegree(number); Console.printDouble(calculationResult); calculationResult=0; } else if(mode.equalsIgnoreCase("R")) { double number=Console.getDoubleInput("\nEnter the value :"); calculationResult=sci.inversesinRadian(number); Console.printDouble(calculationResult); calculationResult=0; } } if(command.equalsIgnoreCase("inversecos")) { String mode=Console.getStringInput ("Type in \"D\" for Degree output\nType in \"R\" to Radians output"); if(mode.equalsIgnoreCase("D")) { double number=Console.getDoubleInput("\nEnter the value :"); calculationResult=sci.inversecosDegree(number); Console.printDouble(calculationResult); calculationResult=0; } else if(mode.equalsIgnoreCase("R")) { double number=Console.getDoubleInput("\nEnter the value :"); calculationResult=sci.inversecosRadians(number); Console.printDouble(calculationResult); calculationResult=0; } } if(command.equalsIgnoreCase("inversetan")) { String mode=Console.getStringInput ("Type in \"D\" for Degree output\nType in \"R\" to Radians output"); if(mode.equalsIgnoreCase("D")) { double number=Console.getDoubleInput("\nEnter the value :"); calculationResult=sci.inversetanDegree(number); Console.printDouble(calculationResult); calculationResult=0; } else if(mode.equalsIgnoreCase("R")) { double number=Console.getDoubleInput("\nEnter the value :"); calculationResult=sci.inversetanRadians(number); Console.printDouble(calculationResult); calculationResult=0; } } if(command.equalsIgnoreCase("temperature")) { String userInput = Console.getStringInput ("Type in \"c\" to convert Celcius to Farhenheit\nType in \"f\" to convert Farhenheit to Celcius"); if(userInput.equalsIgnoreCase("c")) { double temp=Console.getDoubleInput("\nEnter the temperature in Celcius :"); double result=custom.celciustoFarhenheat(temp); //System.out.println(temp+"Celcius to f calculationResult = result; Console.printDouble(result); } else if(userInput.equalsIgnoreCase("f")) { double temp=Console.getDoubleInput("\nEnter the temperature in Farhenheit :"); double result=custom.farhenheatTocelcius(temp); calculationResult = result; Console.printDouble(result); } } if(command.equalsIgnoreCase("unit")) { String userInput=Console.getStringInput ("Type in \"D\" to convert Degree to Radians\nType in \"R\" to convert Radians to Degree"); if(userInput.equalsIgnoreCase("D")) { double deg=Console.getDoubleInput("\nType in Degree to display the Radian value:"); double result=sci.degToradian(deg); //System.out.println(temp+"Celcius to f Console.printDouble(result); } if(userInput.equalsIgnoreCase("R")) { double rad=Console.getDoubleInput("\nType in Radian to display the Degree value:"); double result=sci.radToDegree(rad); Console.printDouble(result); } } //if (userInput.equalsIgnoreCase("Oct")) //Memory if (command.equalsIgnoreCase("Memory")){ double memInput = Console.getDoubleInput("Please enter in a numeric value to save: "); mem = memInput; System.out.println("The value (" + mem + ") has been saved to the memory."); } //Memory + if (command.equalsIgnoreCase("M+")){ double memAdd = mem + calculationResult; //calculationResult = memAdd; System.out.println("Saved value (" + mem + ") has been added to the current value (" + calculationResult + ")."); calculationResult = memAdd; } //Memory reset if (command.equalsIgnoreCase("MC")){ if (mem != 0){ mem = 0; System.out.println("Reset memory value."); } else{ System.out.println("Reset memory value."); } } //Display memory if (command.equalsIgnoreCase("MRC")){ calculationResult = mem; System.out.println("Recall memory value."); } //Addition if (command.equalsIgnoreCase("add")){ if(calculationResult != 0){ double firstNumb = calculationResult; double secondNumb = Console.getDoubleInput("Type in the second number you wish to add: "); calculationResult = firstNumb + secondNumb; //double x = calculationResult; //calculationResult = cor.add(x); defaultCalcResult = calculationResult; } else{ double firstNumb = Console.getDoubleInput("Type in the first number you wish to add: "); double secondNumb = Console.getDoubleInput("Type in the second number you wish to add: "); calculationResult = firstNumb + secondNumb; defaultCalcResult = calculationResult; } //double firstNumb = Console.getDoubleInput("Type in the first number you wish to add: "); //double secondNumb = Console.getDoubleInput("Type in the second number you wish to add: "); //calculationResult = firstNumb + secondNumb; //defaultCalcResult = calculationResult; System.out.println("The sum of two number is: " + calculationResult); //Console.println(firstNumb); } //Subtraction if (command.equalsIgnoreCase("subtract")){ if(calculationResult != 0){ double firstNumb = calculationResult; double secondNumb = Console.getDoubleInput("Type in the second number you wish to subtract: "); calculationResult = cor.subtract(firstNumb, secondNumb); defaultCalcResult = calculationResult; } else{ double firstNumb = Console.getDoubleInput("Type in the first number you wish to subtract: "); double secondNumb = Console.getDoubleInput("Type in the second number you wish to subtract: "); calculationResult = cor.subtract(firstNumb, secondNumb); defaultCalcResult = calculationResult; } System.out.println("The difference of the two number is: " + calculationResult); } //Multiplication if (command.equalsIgnoreCase("multiply")){ if(calculationResult != 0){ double firstNumb = calculationResult; double secondNumb = Console.getDoubleInput("Type in the second number you wish to multiply: "); calculationResult = cor.multiply(firstNumb, secondNumb); System.out.println("The multiplication of the two number is: " + calculationResult); } else{ double firstNumb = Console.getDoubleInput("Type in the first number you wish to multiply: "); double secondNumb = Console.getDoubleInput("Type in the second number you wish to multiply: "); calculationResult = cor.multiply(firstNumb, secondNumb); System.out.println("The multiplication of the two number is: " + calculationResult); } } //Division if (command.equalsIgnoreCase("divide")){ if (calculationResult != 0){ double firstNumb = calculationResult; double secondNumb = Console.getDoubleInput("Type in the divisor: "); calculationResult = cor.divide(firstNumb, secondNumb); System.out.println("The division of the two number is: " + calculationResult); } else{ double firstNumb = Console.getDoubleInput("Type in the dividend: "); double secondNumb = Console.getDoubleInput("Type in the divisor: "); calculationResult = firstNumb / secondNumb; System.out.println("The division of the two number is: " + calculationResult); } } //Distance conversion *Custom Feature* if (command.equalsIgnoreCase("distance")){ //System.out.println("[Current distance is set to Km]"); String userInput = Console.getStringInput( "Please select from the following options: \nType in \"km \"to convert Kilometers to Miles\nType in \"Mi \"to convert Miles to Kilometers"); //Kilimeter conversion if (userInput.equalsIgnoreCase("km")){ double firstNumb = Console.getDoubleInput( "Type in the numeric distance you wish to convert to miles: "); conversionResult = cust.kmToMiles(firstNumb); calculationResult = conversionResult; System.out.println(firstNumb + "Km(s) in mile(s) is: " + calculationResult); } //Mile conversion if(userInput.equalsIgnoreCase("Mi")){ double firstNumb = Console.getDoubleInput( "Type in the numeric distance you wish to convert to kilometers: "); conversionResult = cust.milesToKm(firstNumb); calculationResult = conversionResult; System.out.println(firstNumb + "mile(s) in Km(s) is: " + calculationResult); } } // else{ // System.out.println("Invalid command! Please enter a valid command"); // } // Console.println("Welcome to my calculator!"); // String s = Console.getStringInput("Enter a string"); // Integer i = Console.getIntegerInput("Enter an integer"); // Double d = Console.getDoubleInput("Enter a double."); // Console.println("The user input %s as a string", s); // Console.println("The user input %s as a integer", i); // Console.println("The user input %s as a d", d); //String output = Console.getStringInput("type something"); //Console.println(output); //public void runCommandLoop() // Scanner input = new Scanner(System.in); // Scanner input2 = new Scanner(System.in); // while (true) { // System.out.print("Enter a command: "); // String command = input.next(); // if (command.equalsIgnoreCase("exit")){ // System.out.print("Thanks for calculating with us!"); // break; // } // if (command.equalsIgnoreCase("add")){ // double firstNumb = Console.getDoubleInput("Type in the first number you wish to add: "); // double secondNumb = Console.getDoubleInput("Type in the second number you wish to add: "); // //Console.println(firstNumb); // } // } } catch(Exception e) { System.out.println("An error has occured"); continue; } } } }