From 3818e41eb82f6c7f9da9563b7ba6a7ee4739b580 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Sat, 30 Oct 2021 16:55:21 -0400 Subject: [PATCH 01/13] changed console to 2 doubles --- .../com/zipcodewilmington/scientificcalculator/Console.java | 5 ----- .../scientificcalculator/MainApplication.java | 6 ++++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 83f0e97f..56b821e5 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -21,11 +21,6 @@ public static String getStringInput(String prompt) { String userInput = scanner.nextLine(); return userInput; } - - public static Integer getIntegerInput(String prompt) { - return null; - } - public static Double getDoubleInput(String prompt) { return null; } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 5f421325..d073e789 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -4,14 +4,16 @@ * Created by leon on 2/9/18. */ public class MainApplication { + public static void main(String[] args) { 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."); + Double d1 = Console.getDoubleInput("Enter a double."); + Double d2 = Console.getDoubleInput("Enter another 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); } + public static void } From 0d5dcfbec27364f4ef52a7388678d31dae09bf8e Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Sat, 30 Oct 2021 20:46:50 -0400 Subject: [PATCH 02/13] gave skeleton while loop and switch statement onto skeleton methods --- pom.xml | 4 + .../scientificcalculator/MainApplication.java | 95 +++++++++++++++++-- 2 files changed, 90 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index e7cb4f6b..001e74fb 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,10 @@ com.zipcodewilmington scientific_calculator 1.0-SNAPSHOT + + 11 + 11 + \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index d073e789..2449a15c 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -1,19 +1,96 @@ package com.zipcodewilmington.scientificcalculator; +import java.util.Locale; + /** * Created by leon on 2/9/18. */ public class MainApplication { - + public static int display = 0; public static void main(String[] args) { Console.println("Welcome to my calculator!"); - String s = Console.getStringInput("Enter a string"); - Double d1 = Console.getDoubleInput("Enter a double."); - Double d2 = Console.getDoubleInput("Enter another 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); + while(!(s.equals("kill")){ + String s = Console.getStringInput("What do you want to do?"); + //Double d1 = Console.getDoubleInput("Enter a double."); + //Double d2 = Console.getDoubleInput("Enter another double."); + //Console.println("The user input %s as a string", s); + //Console.println("The user input %s as a d", d1); + //Console.println("The user input %s as a d", d2); + switch (s.toLowerCase()) { + case "current number": + break; + case "clear screen": + break; + case "change current number": + break; + case "add": + break; + case "subtract": + break; + case "multiply": + break; + case "divide": + break; + case "square": + break; + case "square root": + break; + case "variable exponent": + break; + case "inverse": + break; + case "switch display mode": + break; + case "binary": + break; + case "decimal": + break; + case "octal": + break; + case "hexadecimal": + break; + case "add to memory": + break; + case "clear memory": + break; + case "replace memory": + break; + case "sin": + break; + case "cos": + break; + case "tan": + break; + case "inv sin": + break; + case "inv cos": + break; + case "inv tan": + break; + case "switch units mode": + break; + case "radians": + break; + case "degrees": + break; + case "log": + break; + case "inv log": + break; + case "ln": + break; + case "inv ln": + break; + case "factorial": + break; + case "absolute value": + break; + case "kill": + break; + default: + System.println("Cannot compute. Please try again"); + break; + } + } } - public static void } From 766b85643871133d3b922c03a2415a656ba0a2ad Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Sat, 30 Oct 2021 21:42:31 -0400 Subject: [PATCH 03/13] Skeleton methods finished --- .../scientificcalculator/Console.java | 5 +- .../scientificcalculator/MainApplication.java | 73 ++++++++++++++++++- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 56b821e5..3647a164 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -22,6 +22,9 @@ public static String getStringInput(String prompt) { return userInput; } public static Double getDoubleInput(String prompt) { - return null; + Scanner scanner = new Scanner(System.in); + println(prompt); + Double userInput = scanner.nextDouble(); + return userInput; } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 2449a15c..b6027666 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -6,9 +6,15 @@ * Created by leon on 2/9/18. */ public class MainApplication { - public static int display = 0; + public static double display = 0; //ie current number + public static String unitsMode = "degrees"; + public static String displayMode = "decimal"; + public static double memory = 0; public static void main(String[] args) { Console.println("Welcome to my calculator!"); + //THINGS TO ADD STILL: NEGATIVE/POSITIVE; EXCEPTION/ERROR HANDLING FORCING A CLEAR; + //STANDARDIZE THE PRINTING FORMAT FOR WHEN ANSWERS GET PUMPED OUT + //Negative (Math.negateExact()?) while(!(s.equals("kill")){ String s = Console.getStringInput("What do you want to do?"); //Double d1 = Console.getDoubleInput("Enter a double."); @@ -18,74 +24,127 @@ public static void main(String[] args) { //Console.println("The user input %s as a d", d2); switch (s.toLowerCase()) { case "current number": + //print current number break; case "clear screen": + clearScreen(); break; case "change current number": + double newnum = 0; + //get user input; + display = newnum; break; case "add": + double adder = 0; + //take user input here + add(adder); break; case "subtract": + double subber = 0; + //take user input here + subtract(subber); break; case "multiply": + double multer = 0; + //take user input here + multiply(multer); break; case "divide": + //perfect spot for error testing + double divver = 0; + //take user input here + divide(divver); break; case "square": + display*display; break; case "square root": + Math.sqrt(display); break; case "variable exponent": + double exponent = 0; + //take user input here + Math.pow(display,exponent); break; case "inverse": + (float) 1/display; break; case "switch display mode": + //how to have optional input? + switchDisplayMode(); break; case "binary": + switchDisplayMode("binary"); break; case "decimal": + switchDisplayMode("decimal"); break; case "octal": + switchDisplayMode("octal"); break; case "hexadecimal": + switchDisplayMode("hexadecimal"); break; case "add to memory": + //have prompts here or in memorize + double memorize = 0; + //get user input here + memory = memorize; break; case "clear memory": + memory = 0; break; - case "replace memory": + case "recall memory": + //print memory here break; case "sin": + Math.sin(display); break; case "cos": + Math.cos(display); break; case "tan": + Math.tan(display); break; case "inv sin": + 1 / Math.sin(display); break; case "inv cos": + 1 / Math.cos(display); break; case "inv tan": + 1 / Math.tan(display); break; case "switch units mode": + switchUnitsMode(); break; case "radians": + switchUnitsMode("radians"); break; case "degrees": + switchUnitsMode("degrees"); break; case "log": + Math.log10(display); break; case "inv log": + Math.pow(10,display); break; case "ln": + Math.log(display); break; case "inv ln": + Math.exp(display); break; case "factorial": + //there was no readily available factorial function I could find; for now we make our own + factorial(); break; case "absolute value": + Math.abs(display); break; case "kill": + //Print kill message break; default: System.println("Cannot compute. Please try again"); @@ -93,4 +152,14 @@ public static void main(String[] args) { } } } + public static void clearScreen() {} + public static double add(double adder){return 0;} + public static double subtract(double subber){return 0;} + public static double multiply(double multer){return 0;} + public static double divide(double divver){return 0;} + //2 following functions should have OPTIONAL parameters (idk how to do this for now, but im pretty sure its possible) + public static String switchDisplayMode(String mode){return null;} + public static String switchUnitsMode(String mode){return null;} + //not sure what a factorial function would take as parameter(s) + public static double factorial(){return 0;} } From 1261941bff1b270fec9a413042a96c0473f2b614 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Sun, 31 Oct 2021 15:51:55 -0400 Subject: [PATCH 04/13] Sketchedout a couple of methods onto configuring display --- .../scientificcalculator/MainApplication.java | 91 +++++++++++++------ 1 file changed, 61 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index b6027666..80c712a6 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -15,8 +15,9 @@ public static void main(String[] args) { //THINGS TO ADD STILL: NEGATIVE/POSITIVE; EXCEPTION/ERROR HANDLING FORCING A CLEAR; //STANDARDIZE THE PRINTING FORMAT FOR WHEN ANSWERS GET PUMPED OUT //Negative (Math.negateExact()?) - while(!(s.equals("kill")){ - String s = Console.getStringInput("What do you want to do?"); + String s = ""; + while(!(s.equals("kill"))){ + s = Console.getStringInput("What do you want to do?"); //Double d1 = Console.getDoubleInput("Enter a double."); //Double d2 = Console.getDoubleInput("Enter another double."); //Console.println("The user input %s as a string", s); @@ -24,54 +25,49 @@ public static void main(String[] args) { //Console.println("The user input %s as a d", d2); switch (s.toLowerCase()) { case "current number": + Console.println("The current number is: %s",display); //print current number break; case "clear screen": clearScreen(); break; case "change current number": - double newnum = 0; - //get user input; - display = newnum; + display = Console.getDoubleInput("Give me a new current number"); + Console.println("The new number is %s.",display); break; case "add": - double adder = 0; - //take user input here - add(adder); + double adder = Console.getDoubleInput("Give me the number to add to the display"); + Console.println("The sum of %s and %s is %s.",display,adder,add(adder)); break; case "subtract": - double subber = 0; - //take user input here - subtract(subber); + double subber = Console.getDoubleInput("Give me the number to subtract from the display"); + Console.println("The difference of %s and %s is %s.",display,subber,subtract(subber)); break; case "multiply": - double multer = 0; - //take user input here - multiply(multer); + double multer = Console.getDoubleInput("Give me the number to multiply the display by"); + Console.println("The product of %s and %s is %s.",display,multer,multiply(multer)); break; case "divide": //perfect spot for error testing - double divver = 0; - //take user input here - divide(divver); + double divver = Console.getDoubleInput("Give me the number to divide the display by"); + Console.println("The quotient of %s and %s is %s.",display,divver,divide(divver)); break; case "square": - display*display; + Console.println("The square of %s is %s.",display,display * display); break; case "square root": - Math.sqrt(display); + Console.println("The square root of %s is %s.",display,Math.sqrt(display)); break; case "variable exponent": - double exponent = 0; - //take user input here - Math.pow(display,exponent); + double exponent = Console.getDoubleInput("What power should I raise the display to?"); + Console.println("%s to the %sth power is %s",display,exponent,Math.pow(display,exponent)); break; case "inverse": - (float) 1/display; + Console.println("The inverse of %s is %s",display,(float) (1/ display)); break; case "switch display mode": - //how to have optional input? - switchDisplayMode(); + //how to have optional input? (TRYING OVERLOADING) + Console.println("The display mode is now: %s",switchDisplayMode()); break; case "binary": switchDisplayMode("binary"); @@ -152,12 +148,47 @@ public static void main(String[] args) { } } } - public static void clearScreen() {} - public static double add(double adder){return 0;} - public static double subtract(double subber){return 0;} - public static double multiply(double multer){return 0;} - public static double divide(double divver){return 0;} + //I have no idea if this will work or not + public static void clearScreen() { + System.out.print("\033[H\033[2J"); + System.out.flush(); + } + public static double add(double adder){ + return display + adder; + } + public static double subtract(double subber){ + return display - subber; + } + public static double multiply(double multer){ + return display * multer; + } + public static double divide(double divver){ + return display / divver; + } //2 following functions should have OPTIONAL parameters (idk how to do this for now, but im pretty sure its possible) + public static String switchDisplayMode(){ + switch(displayMode){ + case "decimal": + displayMode = "hexadecimal"; + switchDisplayMode("hexadecimal"); + return displayMode; + case "hexadecimal": + displayMode = "binary"; + switchDisplayMode("binary"); + return displayMode; + case "binary": + displayMode = "octal"; + switchDisplayMode("octal"); + return displayMode; + case "octal": + displayMode = "decimal"; + switchDisplayMode("decimal"); + return displayMode; + default: + displayMode = "This should never be returned"; + return displayMode; + } + } public static String switchDisplayMode(String mode){return null;} public static String switchUnitsMode(String mode){return null;} //not sure what a factorial function would take as parameter(s) From d17aa0fd412d8fc1fc4112bed24a68a06f6937f8 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Sun, 31 Oct 2021 16:13:02 -0400 Subject: [PATCH 05/13] Allowed displaymode methods to switch value of displaymode accordingly --- .../scientificcalculator/MainApplication.java | 59 +++++++++++++++---- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 80c712a6..7f5b9740 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -16,13 +16,12 @@ public static void main(String[] args) { //STANDARDIZE THE PRINTING FORMAT FOR WHEN ANSWERS GET PUMPED OUT //Negative (Math.negateExact()?) String s = ""; + // while(!(s.equals("kill"))){ s = Console.getStringInput("What do you want to do?"); //Double d1 = Console.getDoubleInput("Enter a double."); //Double d2 = Console.getDoubleInput("Enter another double."); //Console.println("The user input %s as a string", s); - //Console.println("The user input %s as a d", d1); - //Console.println("The user input %s as a d", d2); switch (s.toLowerCase()) { case "current number": Console.println("The current number is: %s",display); @@ -70,16 +69,16 @@ public static void main(String[] args) { Console.println("The display mode is now: %s",switchDisplayMode()); break; case "binary": - switchDisplayMode("binary"); + Console.println("The display mode is now: %s",switchDisplayMode("binary")); break; case "decimal": - switchDisplayMode("decimal"); + Console.println("The display mode is now: %s",switchDisplayMode("decimal")); break; case "octal": - switchDisplayMode("octal"); + Console.println("The display mode is now: %s",switchDisplayMode("octal")); break; case "hexadecimal": - switchDisplayMode("hexadecimal"); + Console.println("The display mode is now: %s",switchDisplayMode("hexadecimal")); break; case "add to memory": //have prompts here or in memorize @@ -143,7 +142,7 @@ public static void main(String[] args) { //Print kill message break; default: - System.println("Cannot compute. Please try again"); + Console.println("Cannot compute. Please try again"); break; } } @@ -165,31 +164,65 @@ public static double multiply(double multer){ public static double divide(double divver){ return display / divver; } - //2 following functions should have OPTIONAL parameters (idk how to do this for now, but im pretty sure its possible) public static String switchDisplayMode(){ switch(displayMode){ case "decimal": displayMode = "hexadecimal"; - switchDisplayMode("hexadecimal"); return displayMode; case "hexadecimal": displayMode = "binary"; - switchDisplayMode("binary"); return displayMode; case "binary": displayMode = "octal"; - switchDisplayMode("octal"); return displayMode; case "octal": displayMode = "decimal"; - switchDisplayMode("decimal"); return displayMode; default: displayMode = "This should never be returned"; return displayMode; } } - public static String switchDisplayMode(String mode){return null;} + public static String switchDisplayMode(String mode){ + switch(mode){ + case "decimal": + displayMode = "decimal"; + return displayMode; + case "hexadecimal": + displayMode = "hexadecimal"; + return displayMode; + case "binary": + displayMode = "binary"; + return displayMode; + case "octal": + displayMode = "octal"; + return displayMode; + default: + displayMode = "This should never be returned"; + return displayMode; + } + + } + public static String displayPrint(String original){ + switch(displayMode){ + case "decimal": + displayMode = "decimal"; + return displayMode; + case "hexadecimal": + displayMode = "hexadecimal"; + return displayMode; + case "binary": + displayMode = "binary"; + return displayMode; + case "octal": + displayMode = "octal"; + return displayMode; + default: + displayMode = "This should never be returned"; + return displayMode; + } + } + public static String switchUnitsMode(String mode){return null;} //not sure what a factorial function would take as parameter(s) public static double factorial(){return 0;} From d5943499768f49027c1ea3ec2befa5ac24f3d86c Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Sun, 31 Oct 2021 17:16:09 -0400 Subject: [PATCH 06/13] Added functionality to the displaymodes --- .../scientificcalculator/MainApplication.java | 76 +++++++++++++------ 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 7f5b9740..63d5bf80 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -6,6 +6,7 @@ * Created by leon on 2/9/18. */ public class MainApplication { + public static double display = 0; //ie current number public static String unitsMode = "degrees"; public static String displayMode = "decimal"; @@ -24,7 +25,7 @@ public static void main(String[] args) { //Console.println("The user input %s as a string", s); switch (s.toLowerCase()) { case "current number": - Console.println("The current number is: %s",display); + Console.println("The current number is: %s",displayPrint(display)); //print current number break; case "clear screen": @@ -32,53 +33,59 @@ public static void main(String[] args) { break; case "change current number": display = Console.getDoubleInput("Give me a new current number"); - Console.println("The new number is %s.",display); + Console.println("The new number is %s.",displayPrint(display)); break; case "add": double adder = Console.getDoubleInput("Give me the number to add to the display"); - Console.println("The sum of %s and %s is %s.",display,adder,add(adder)); + Console.println("The sum of %s and %s is %s.",displayPrint(display),displayPrint(adder),displayPrint(add(adder))); break; case "subtract": double subber = Console.getDoubleInput("Give me the number to subtract from the display"); - Console.println("The difference of %s and %s is %s.",display,subber,subtract(subber)); + Console.println("The difference of %s and %s is %s.",displayPrint(display),displayPrint(subber),displayPrint(subtract(subber))); break; case "multiply": double multer = Console.getDoubleInput("Give me the number to multiply the display by"); - Console.println("The product of %s and %s is %s.",display,multer,multiply(multer)); + Console.println("The product of %s and %s is %s.",displayPrint(display),displayPrint(multer),displayPrint(multiply(multer))); break; case "divide": //perfect spot for error testing double divver = Console.getDoubleInput("Give me the number to divide the display by"); - Console.println("The quotient of %s and %s is %s.",display,divver,divide(divver)); + Console.println("The quotient of %s and %s is %s.",displayPrint(display),displayPrint(divver),displayPrint(divide(divver))); break; case "square": - Console.println("The square of %s is %s.",display,display * display); + Console.println("The square of %s is %s.",displayPrint(display),display * display); break; case "square root": - Console.println("The square root of %s is %s.",display,Math.sqrt(display)); + Console.println("The square root of %s is %s.",displayPrint(display),displayPrint(Math.sqrt(display))); break; case "variable exponent": double exponent = Console.getDoubleInput("What power should I raise the display to?"); - Console.println("%s to the %sth power is %s",display,exponent,Math.pow(display,exponent)); + Console.println("%s to the %sth power is %s",displayPrint(display),displayPrint(exponent),displayPrint(Math.pow(display,exponent))); break; case "inverse": - Console.println("The inverse of %s is %s",display,(float) (1/ display)); + Console.println("The inverse of %s is %s",displayPrint(display), displayPrint((float) (1/ display))); break; case "switch display mode": //how to have optional input? (TRYING OVERLOADING) Console.println("The display mode is now: %s",switchDisplayMode()); + Console.println("Loss of data is possible if you switch display modes, input data must be decimal"); + break; case "binary": Console.println("The display mode is now: %s",switchDisplayMode("binary")); + Console.println("Loss of data is possible if you switch display modes, input data must be decimal"); break; case "decimal": Console.println("The display mode is now: %s",switchDisplayMode("decimal")); + Console.println("Loss of data is possible if you switch display modes, input data must be decimal"); break; case "octal": Console.println("The display mode is now: %s",switchDisplayMode("octal")); + Console.println("Loss of data is possible if you switch display modes, input data must be decimal"); break; case "hexadecimal": Console.println("The display mode is now: %s",switchDisplayMode("hexadecimal")); + Console.println("Loss of data is possible if you switch display modes, input data must be decimal"); break; case "add to memory": //have prompts here or in memorize @@ -201,25 +208,50 @@ public static String switchDisplayMode(String mode){ displayMode = "This should never be returned"; return displayMode; } - +//must somehow accept doubles, floats and ints } - public static String displayPrint(String original){ + /** + public static String displayPrint(int original){ switch(displayMode){ case "decimal": - displayMode = "decimal"; - return displayMode; + return Integer.valueOf(original).toString(); case "hexadecimal": - displayMode = "hexadecimal"; - return displayMode; + return Integer.toHexString(original); case "binary": - displayMode = "binary"; - return displayMode; + return Integer.toBinaryString(original); case "octal": - displayMode = "octal"; - return displayMode; + return Integer.toOctalString(original); + } + */ + public static String displayPrint(float original){ + int binoct = Math.toIntExact(Float.valueOf(original).longValue()); + switch(displayMode){ + case "decimal": + return Float.valueOf(original).toString(); + case "hexadecimal": + return Float.toHexString(original); + case "binary": + return Integer.toBinaryString(binoct); + case "octal": + return Integer.toOctalString(binoct); default: - displayMode = "This should never be returned"; - return displayMode; + return "This should never be returned"; + } + } + public static String displayPrint(double original){ + //LOSS OF DATA IS POSSIBLE HERE + int binoct = Math.toIntExact(Double.valueOf(original).longValue()); + switch(displayMode){ + case "decimal": + return Double.valueOf(original).toString(); + case "hexadecimal": + return Double.toHexString(original); + case "binary": + return Integer.toBinaryString(binoct); + case "octal": + return Integer.toOctalString(binoct); + default: + return "This should never be returned"; } } From 3b21097a119a4eed2d5137fff477fd0ea8d3302f Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Sun, 31 Oct 2021 19:15:44 -0400 Subject: [PATCH 07/13] Added trig functionality --- .../scientificcalculator/MainApplication.java | 56 +++++++++++++------ .../TestMainApplication.java | 1 + 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 63d5bf80..3e4d617a 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -88,43 +88,41 @@ public static void main(String[] args) { Console.println("Loss of data is possible if you switch display modes, input data must be decimal"); break; case "add to memory": - //have prompts here or in memorize - double memorize = 0; - //get user input here - memory = memorize; + memory = Console.getDoubleInput("Give me the number to memorize"); + Console.println("The new memorized number is %s.",displayPrint(memory)); break; case "clear memory": memory = 0; break; case "recall memory": - //print memory here + Console.println("The memorized number is %s.",displayPrint(memory)); break; case "sin": - Math.sin(display); + Console.println("The sine of %s is %s", displayPrint(display),displayPrint(Math.sin(unitter(display)))); break; case "cos": - Math.cos(display); + Console.println("The cosine of %s is %s", displayPrint(display),displayPrint(Math.cos(unitter(display)))); break; case "tan": - Math.tan(display); + Console.println("The tangent of %s is %s", displayPrint(display),displayPrint(Math.tan(unitter(display)))); break; case "inv sin": - 1 / Math.sin(display); + Console.println("The inverse sine of %s is %s", displayPrint(display),displayPrint( (float)(1 / (Math.sin(unitter(display)))))); break; case "inv cos": - 1 / Math.cos(display); + Console.println("The inverse cosine of %s is %s", displayPrint(display),displayPrint( (float)(1 / (Math.cos(unitter(display)))))); break; case "inv tan": - 1 / Math.tan(display); + Console.println("The inverse tangent of %s is %s", displayPrint(display),displayPrint( (float)(1 / (Math.tan(unitter(display)))))); break; case "switch units mode": - switchUnitsMode(); + Console.println("The units mode is now: %s",switchUnitsMode()); break; case "radians": - switchUnitsMode("radians"); + Console.println("The units mode is now: %s",switchUnitsMode("radians")); break; case "degrees": - switchUnitsMode("degrees"); + Console.println("The units mode is now: %s",switchUnitsMode("degrees")); break; case "log": Math.log10(display); @@ -208,7 +206,7 @@ public static String switchDisplayMode(String mode){ displayMode = "This should never be returned"; return displayMode; } -//must somehow accept doubles, floats and ints +//must somehow accept doubles, floats } /** public static String displayPrint(int original){ @@ -254,8 +252,34 @@ public static String displayPrint(double original){ return "This should never be returned"; } } + public static double unitter(double angle) { + if(unitsMode.equals("degrees")){ + return Math.toRadians(angle); + } + else{ + return angle; + } + } + public static String switchUnitsMode(){ + if(unitsMode.equals("degrees")){ + unitsMode = "radians"; + return unitsMode; + } + else if (unitsMode.equals("radians")){ + unitsMode = "degrees"; + } + return unitsMode; + } - public static String switchUnitsMode(String mode){return null;} + public static String switchUnitsMode(String mode){ + if(mode.equals("degrees")){ + unitsMode = "degrees"; + } + else if (mode.equals("radians")){ + unitsMode = "radians"; + } + return unitsMode; + } //not sure what a factorial function would take as parameter(s) public static double factorial(){return 0;} } diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 94e8d987..6cec4ace 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -4,4 +4,5 @@ * Created by leon on 2/9/18. */ public class TestMainApplication { + } From 39b5855c5fab3530f49a2c15e3e18e9962e9894b Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Sun, 31 Oct 2021 19:24:39 -0400 Subject: [PATCH 08/13] Added log and abs function --- .../scientificcalculator/MainApplication.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 3e4d617a..1afb47f8 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -53,7 +53,7 @@ public static void main(String[] args) { Console.println("The quotient of %s and %s is %s.",displayPrint(display),displayPrint(divver),displayPrint(divide(divver))); break; case "square": - Console.println("The square of %s is %s.",displayPrint(display),display * display); + Console.println("The square of %s is %s.",displayPrint(display),displayPrint(display * display)); break; case "square root": Console.println("The square root of %s is %s.",displayPrint(display),displayPrint(Math.sqrt(display))); @@ -125,16 +125,16 @@ public static void main(String[] args) { Console.println("The units mode is now: %s",switchUnitsMode("degrees")); break; case "log": - Math.log10(display); + Console.println("The log of %s is %s.",displayPrint(display),displayPrint(Math.log10(display))); break; case "inv log": - Math.pow(10,display); + Console.println("The inv log of %s is %s.",displayPrint(display),displayPrint(Math.pow(10,display))); break; case "ln": - Math.log(display); + Console.println("The natural log of %s is %s.",displayPrint(display),displayPrint(Math.log(display))); break; case "inv ln": - Math.exp(display); + Console.println("The inv natural log of %s is %s.",displayPrint(display),displayPrint(Math.exp(display))); break; case "factorial": //there was no readily available factorial function I could find; for now we make our own From d6edffdb4bc2002d6f1d7309cbcf96d532a1fd8a Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Sun, 31 Oct 2021 19:24:57 -0400 Subject: [PATCH 09/13] Added log and abs function --- .../scientificcalculator/MainApplication.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 1afb47f8..26e50f3f 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -141,9 +141,10 @@ public static void main(String[] args) { factorial(); break; case "absolute value": - Math.abs(display); + Console.println("The square of %s is %s.",displayPrint(display),displayPrint(Math.abs(display))); break; case "kill": + //Print kill message break; default: From b118dde621ff56d265cfa7651fbeec5f58a974d7 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Sun, 31 Oct 2021 19:39:59 -0400 Subject: [PATCH 10/13] Added everything except error functionality --- .../scientificcalculator/MainApplication.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 26e50f3f..da96bb7c 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -13,8 +13,7 @@ public class MainApplication { public static double memory = 0; public static void main(String[] args) { Console.println("Welcome to my calculator!"); - //THINGS TO ADD STILL: NEGATIVE/POSITIVE; EXCEPTION/ERROR HANDLING FORCING A CLEAR; - //STANDARDIZE THE PRINTING FORMAT FOR WHEN ANSWERS GET PUMPED OUT + //THINGS TO ADD STILL: EXCEPTION/ERROR HANDLING FORCING A CLEAR; //Negative (Math.negateExact()?) String s = ""; // @@ -65,11 +64,13 @@ public static void main(String[] args) { case "inverse": Console.println("The inverse of %s is %s",displayPrint(display), displayPrint((float) (1/ display))); break; + case "negate": + display = display * -1; + Console.println("The display number of %s has been negated to %s ",displayPrint(display),displayPrint(display * -1)); case "switch display mode": //how to have optional input? (TRYING OVERLOADING) Console.println("The display mode is now: %s",switchDisplayMode()); Console.println("Loss of data is possible if you switch display modes, input data must be decimal"); - break; case "binary": Console.println("The display mode is now: %s",switchDisplayMode("binary")); @@ -137,15 +138,13 @@ public static void main(String[] args) { Console.println("The inv natural log of %s is %s.",displayPrint(display),displayPrint(Math.exp(display))); break; case "factorial": - //there was no readily available factorial function I could find; for now we make our own - factorial(); + Console.println("The factorial of %s is %s.",displayPrint(display),displayPrint(factorial())); break; case "absolute value": Console.println("The square of %s is %s.",displayPrint(display),displayPrint(Math.abs(display))); break; case "kill": - - //Print kill message + Console.println("The calculator will now exit..."); break; default: Console.println("Cannot compute. Please try again"); @@ -168,6 +167,9 @@ public static double multiply(double multer){ return display * multer; } public static double divide(double divver){ + if(divver == 0){ + return + } return display / divver; } public static String switchDisplayMode(){ @@ -282,5 +284,11 @@ else if (mode.equals("radians")){ return unitsMode; } //not sure what a factorial function would take as parameter(s) - public static double factorial(){return 0;} + public static double factorial(){ + double factoria = 0; + for(int i = 1; i <= display;i++){ + factoria = factoria * i; + } + return factoria; + } } From ef5f34deb463131be1d465f432c4e4847637806e Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Sun, 31 Oct 2021 20:14:03 -0400 Subject: [PATCH 11/13] Added a clear function --- .../scientificcalculator/MainApplication.java | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index da96bb7c..4c19618a 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -14,18 +14,12 @@ public class MainApplication { public static void main(String[] args) { Console.println("Welcome to my calculator!"); //THINGS TO ADD STILL: EXCEPTION/ERROR HANDLING FORCING A CLEAR; - //Negative (Math.negateExact()?) String s = ""; - // while(!(s.equals("kill"))){ s = Console.getStringInput("What do you want to do?"); - //Double d1 = Console.getDoubleInput("Enter a double."); - //Double d2 = Console.getDoubleInput("Enter another double."); - //Console.println("The user input %s as a string", s); switch (s.toLowerCase()) { case "current number": Console.println("The current number is: %s",displayPrint(display)); - //print current number break; case "clear screen": clearScreen(); @@ -65,10 +59,8 @@ public static void main(String[] args) { Console.println("The inverse of %s is %s",displayPrint(display), displayPrint((float) (1/ display))); break; case "negate": - display = display * -1; Console.println("The display number of %s has been negated to %s ",displayPrint(display),displayPrint(display * -1)); case "switch display mode": - //how to have optional input? (TRYING OVERLOADING) Console.println("The display mode is now: %s",switchDisplayMode()); Console.println("Loss of data is possible if you switch display modes, input data must be decimal"); break; @@ -140,9 +132,11 @@ public static void main(String[] args) { case "factorial": Console.println("The factorial of %s is %s.",displayPrint(display),displayPrint(factorial())); break; + //extra function #1 case "absolute value": Console.println("The square of %s is %s.",displayPrint(display),displayPrint(Math.abs(display))); break; + //extra function #2 case "kill": Console.println("The calculator will now exit..."); break; @@ -154,8 +148,12 @@ public static void main(String[] args) { } //I have no idea if this will work or not public static void clearScreen() { - System.out.print("\033[H\033[2J"); - System.out.flush(); + try{ + Runtime.getRuntime().exec("clear"); + } + catch (final Exception e){ + System.exit(1); + } } public static double add(double adder){ return display + adder; @@ -167,9 +165,6 @@ public static double multiply(double multer){ return display * multer; } public static double divide(double divver){ - if(divver == 0){ - return - } return display / divver; } public static String switchDisplayMode(){ @@ -209,7 +204,6 @@ public static String switchDisplayMode(String mode){ displayMode = "This should never be returned"; return displayMode; } -//must somehow accept doubles, floats } /** public static String displayPrint(int original){ From e246bc241183b924682e11316631214158644542 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Sun, 31 Oct 2021 22:24:38 -0400 Subject: [PATCH 12/13] Made every switch case testable --- .../scientificcalculator/MainApplication.java | 100 ++++++++++++------ 1 file changed, 67 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 4c19618a..c6a50b2c 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -19,122 +19,156 @@ public static void main(String[] args) { s = Console.getStringInput("What do you want to do?"); switch (s.toLowerCase()) { case "current number": - Console.println("The current number is: %s",displayPrint(display)); + String curNumStr = String.format("The current number is: %s",displayPrint(display)); break; case "clear screen": clearScreen(); break; case "change current number": display = Console.getDoubleInput("Give me a new current number"); - Console.println("The new number is %s.",displayPrint(display)); + String changeCurStr = String.format("The new number is %s.",displayPrint(display)); + Console.println(changeCurStr); break; case "add": double adder = Console.getDoubleInput("Give me the number to add to the display"); - Console.println("The sum of %s and %s is %s.",displayPrint(display),displayPrint(adder),displayPrint(add(adder))); + String addStr = String.format("The sum of %s and %s is %s.",displayPrint(display),displayPrint(adder),displayPrint(add(adder))); + Console.println(addStr); break; case "subtract": double subber = Console.getDoubleInput("Give me the number to subtract from the display"); - Console.println("The difference of %s and %s is %s.",displayPrint(display),displayPrint(subber),displayPrint(subtract(subber))); + String subStr = String.format("The difference of %s and %s is %s.",displayPrint(display),displayPrint(subber),displayPrint(subtract(subber))); + Console.println(subStr); break; case "multiply": double multer = Console.getDoubleInput("Give me the number to multiply the display by"); - Console.println("The product of %s and %s is %s.",displayPrint(display),displayPrint(multer),displayPrint(multiply(multer))); + String mulStr = String.format("The product of %s and %s is %s.",displayPrint(display),displayPrint(multer),displayPrint(multiply(multer))); + Console.println(mulStr); break; case "divide": //perfect spot for error testing double divver = Console.getDoubleInput("Give me the number to divide the display by"); - Console.println("The quotient of %s and %s is %s.",displayPrint(display),displayPrint(divver),displayPrint(divide(divver))); + String divStr = String.format("The quotient of %s and %s is %s.",displayPrint(display),displayPrint(divver),displayPrint(divide(divver))); + Console.println(divStr); break; case "square": - Console.println("The square of %s is %s.",displayPrint(display),displayPrint(display * display)); + String squstr = String.format("The square of %s is %s.",displayPrint(display),displayPrint(display * display)); + Console.println(squstr); break; case "square root": - Console.println("The square root of %s is %s.",displayPrint(display),displayPrint(Math.sqrt(display))); + String sqrtstr = String.format("The square root of %s is %s.",displayPrint(display),displayPrint(Math.sqrt(display))); + Console.println(sqrtstr); break; case "variable exponent": double exponent = Console.getDoubleInput("What power should I raise the display to?"); - Console.println("%s to the %sth power is %s",displayPrint(display),displayPrint(exponent),displayPrint(Math.pow(display,exponent))); + String expstr = String.format("%s to the %sth power is %s",displayPrint(display),displayPrint(exponent),displayPrint(Math.pow(display,exponent))); + Console.println(expstr); break; case "inverse": - Console.println("The inverse of %s is %s",displayPrint(display), displayPrint((float) (1/ display))); + String invstr = String.format("The inverse of %s is %s",displayPrint(display), displayPrint((float) (1/ display))); + Console.println(invstr); break; case "negate": - Console.println("The display number of %s has been negated to %s ",displayPrint(display),displayPrint(display * -1)); + String negstr = String.format("The display number of %s has been negated to %s ",displayPrint(display),displayPrint(display * -1)); + Console.println(negstr); + break; case "switch display mode": - Console.println("The display mode is now: %s",switchDisplayMode()); + String switchdispstr = String.format("The display mode is now: %s",switchDisplayMode()); Console.println("Loss of data is possible if you switch display modes, input data must be decimal"); + Console.println(switchdispstr); break; case "binary": - Console.println("The display mode is now: %s",switchDisplayMode("binary")); + String binstr = String.format("The display mode is now: %s",switchDisplayMode("binary")); Console.println("Loss of data is possible if you switch display modes, input data must be decimal"); + Console.println(binstr); break; case "decimal": - Console.println("The display mode is now: %s",switchDisplayMode("decimal")); + String decistr = String.format("The display mode is now: %s",switchDisplayMode("decimal")); Console.println("Loss of data is possible if you switch display modes, input data must be decimal"); + Console.println(decistr); break; case "octal": - Console.println("The display mode is now: %s",switchDisplayMode("octal")); + String octalstr = String.format("The display mode is now: %s",switchDisplayMode("octal")); Console.println("Loss of data is possible if you switch display modes, input data must be decimal"); + Console.println(octalstr); break; case "hexadecimal": - Console.println("The display mode is now: %s",switchDisplayMode("hexadecimal")); + String hexstr = String.format("The display mode is now: %s",switchDisplayMode("hexadecimal")); Console.println("Loss of data is possible if you switch display modes, input data must be decimal"); + Console.println(hexstr); break; case "add to memory": memory = Console.getDoubleInput("Give me the number to memorize"); - Console.println("The new memorized number is %s.",displayPrint(memory)); + String addmemstr = String.format("The new memorized number is %s.",displayPrint(memory)); + Console.println(addmemstr); break; case "clear memory": memory = 0; + Console.println("Memory has been cleared"); break; case "recall memory": - Console.println("The memorized number is %s.",displayPrint(memory)); + String recallstr = String.format("The memorized number is %s.",displayPrint(memory)); + Console.println(recallstr); break; case "sin": - Console.println("The sine of %s is %s", displayPrint(display),displayPrint(Math.sin(unitter(display)))); + String sinstr = String.format("The sine of %s is %s", displayPrint(display),displayPrint(Math.sin(unitter(display)))); + Console.println(sinstr); break; case "cos": - Console.println("The cosine of %s is %s", displayPrint(display),displayPrint(Math.cos(unitter(display)))); + String cosstr = String.format("The cosine of %s is %s", displayPrint(display),displayPrint(Math.cos(unitter(display)))); + Console.println(cosstr); break; case "tan": - Console.println("The tangent of %s is %s", displayPrint(display),displayPrint(Math.tan(unitter(display)))); + String tanstr = String.format("The tangent of %s is %s", displayPrint(display),displayPrint(Math.tan(unitter(display)))); + Console.println(tanstr); break; case "inv sin": - Console.println("The inverse sine of %s is %s", displayPrint(display),displayPrint( (float)(1 / (Math.sin(unitter(display)))))); + String cscstr = String.format("The inverse sine of %s is %s", displayPrint(display),displayPrint( (float)(1 / (Math.sin(unitter(display)))))); + Console.println(cscstr); break; case "inv cos": - Console.println("The inverse cosine of %s is %s", displayPrint(display),displayPrint( (float)(1 / (Math.cos(unitter(display)))))); + String secstr = String.format("The inverse cosine of %s is %s", displayPrint(display),displayPrint( (float)(1 / (Math.cos(unitter(display)))))); + Console.println(secstr); break; case "inv tan": - Console.println("The inverse tangent of %s is %s", displayPrint(display),displayPrint( (float)(1 / (Math.tan(unitter(display)))))); + String cotstr = String.format("The inverse tangent of %s is %s", displayPrint(display),displayPrint( (float)(1 / (Math.tan(unitter(display)))))); + Console.println(cotstr); break; case "switch units mode": - Console.println("The units mode is now: %s",switchUnitsMode()); + String switchunitstr = String.format("The units mode is now: %s",switchUnitsMode()); + Console.println(switchunitstr); break; case "radians": - Console.println("The units mode is now: %s",switchUnitsMode("radians")); + String radstr = String.format("The units mode is now: %s",switchUnitsMode("radians")); + Console.println(radstr); break; case "degrees": - Console.println("The units mode is now: %s",switchUnitsMode("degrees")); + String degstr = String.format("The units mode is now: %s",switchUnitsMode("degrees")); + Console.println(degstr); break; case "log": - Console.println("The log of %s is %s.",displayPrint(display),displayPrint(Math.log10(display))); + String logstr = String.format("The log of %s is %s.",displayPrint(display),displayPrint(Math.log10(display))); + Console.println(logstr); break; case "inv log": - Console.println("The inv log of %s is %s.",displayPrint(display),displayPrint(Math.pow(10,display))); + String invlogstr = String.format("The inv log of %s is %s.",displayPrint(display),displayPrint(Math.pow(10,display))); + Console.println(invlogstr); break; case "ln": - Console.println("The natural log of %s is %s.",displayPrint(display),displayPrint(Math.log(display))); + String lnstr = String.format("The natural log of %s is %s.",displayPrint(display),displayPrint(Math.log(display))); + Console.println(lnstr); break; case "inv ln": - Console.println("The inv natural log of %s is %s.",displayPrint(display),displayPrint(Math.exp(display))); + String invlnstr = String.format("The inv natural log of %s is %s.",displayPrint(display),displayPrint(Math.exp(display))); + Console.println(invlnstr); break; case "factorial": - Console.println("The factorial of %s is %s.",displayPrint(display),displayPrint(factorial())); + String facstr = String.format("The factorial of %s is %s.",displayPrint(display),displayPrint(factorial())); + Console.println(facstr); break; //extra function #1 case "absolute value": - Console.println("The square of %s is %s.",displayPrint(display),displayPrint(Math.abs(display))); + String absstr = String.format("The square of %s is %s.",displayPrint(display),displayPrint(Math.abs(display))); + Console.println(absstr); break; //extra function #2 case "kill": From 3b0ddc2062a6acb9beacb05d9ea4138b752f03d9 Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Mon, 1 Nov 2021 02:06:50 -0400 Subject: [PATCH 13/13] addedsometests --- pom.xml | 9 ++ .../TestMainApplication.java | 152 +++++++++++++++++- 2 files changed, 160 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 001e74fb..a02f210f 100644 --- a/pom.xml +++ b/pom.xml @@ -12,5 +12,14 @@ 11 + + + junit + junit + 4.12 + test + + + \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 6cec4ace..c68d122a 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -1,8 +1,158 @@ package com.zipcodewilmington.scientific_calculator; - +import com.sun.tools.javac.Main; +import com.zipcodewilmington.scientificcalculator.MainApplication; +import org.junit.Test; +import static org.junit.Assert.assertEquals; /** * Created by leon on 2/9/18. */ public class TestMainApplication { + public void doubleAssertEquals(double expected, double actual){ + assertEquals(expected, actual, 0.001); + } + + + @Test + public void testAdd(){ + + //given + MainApplication.display = 6.0; + + //when + double result = MainApplication.add(1.2); + + //then + + doubleAssertEquals(7.2,result); + } + + @Test + public void testSubtract(){ + + //given + MainApplication.display = 4.0; + + //when + double result = MainApplication.subtract(2.0); + + //then + doubleAssertEquals(2.0,result); + } + + @Test + public void testMultiply() { + + //given + MainApplication.display = 6.0; + + //when + double result = MainApplication.multiply(2.0); + + //then + doubleAssertEquals(12.0, result); + } + + @Test + public void testDivide() { + + //given + MainApplication.display = 4.0; + + //when + double result = MainApplication.divide(2.0); + + //then + doubleAssertEquals(2.0, result); + } + + @Test + public void testSwitchDisplayMode() { + + //given + MainApplication.displayMode = "decimal"; + + //when + String nextDisplayMode = MainApplication.switchDisplayMode(); + + //then + assertEquals("hexadecimal",nextDisplayMode); + } + + @Test + public void testDisplayMode() { + + //given + MainApplication.displayMode = "hexadecimal"; + + //when + String nextDisplayMode = MainApplication.switchDisplayMode(); + + //then + assertEquals("binary", nextDisplayMode); + } + + @Test + public void switchTestDisplayMode() { + + //given + MainApplication.displayMode = "binary"; + + //when + String nextDisplayMode = MainApplication.switchDisplayMode(); + + //then + assertEquals("octal", nextDisplayMode); + } + + @Test + public void testSwitchDisplayMode1() { + + //given + MainApplication.displayMode = "octal"; + + //when + String nextDisplayMode = MainApplication.switchDisplayMode(); + + //then + assertEquals("decimal", nextDisplayMode); + } + + @Test + public void testSwitchDisplayMode1() { + + //given + MainApplication.displayMode = "decimal"; + + //when + String nextDisplayMode = MainApplication.switchDisplayMode(); + + //then + assertEquals("decimal", nextDisplayMode); + } + + @Test + public void testSwitchDisplayMode1() { + + //given + MainApplication.displayMode = "binary"; + + //when + String nextDisplayMode = MainApplication.switchDisplayMode(()); + + //then + assertEquals("binary", nextDisplayMode); + } + +@Test + public void switchUnitsMode() { + MainApplication.unitsMode = "degress"; + String nextDisplayMode = MainApplication.switchUnitsMode(); + assertEquals("degrees", nextDisplayMode); } +} + + +} + +