123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537 |
- 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;
- }
-
- }
-
-
-
- }
- }
|