From cc839beb411a4539b2c0fe552b43c136ad92cf61 Mon Sep 17 00:00:00 2001 From: jenn-182 Date: Sat, 12 Jul 2025 13:12:03 -0400 Subject: [PATCH 01/17] core features, still working on tests --- Calc-java | 1 + .../scientificcalculator/CoreFeatures.java | 125 ++++++++++++++++++ .../TestMainApplication.java | 115 ++++++++++++++++ 3 files changed, 241 insertions(+) create mode 160000 Calc-java create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java diff --git a/Calc-java b/Calc-java new file mode 160000 index 0000000..fcb06d0 --- /dev/null +++ b/Calc-java @@ -0,0 +1 @@ +Subproject commit fcb06d06ff91a20dad5d4fbbb679f47c802c6de5 diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java new file mode 100644 index 0000000..5c9d72a --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java @@ -0,0 +1,125 @@ +package com.zipcodewilmington.scientificcalculator; + +public class CoreFeatures { + + //a state represening the value currently displayed on the calc + private double displayValue; + + //Update the display to ERR if an error occurs (divide by 0) + private boolean errorState; + + //initiate calculator with 0 as default + public CoreFeatures () { + this.displayValue = 0.0; + this.errorState=false; + + } + + //Get the current # on the display + public double getDisplayValue() { + return this.displayValue; + } + + //Check for errors + public boolean inErrorState() { + return this.errorState; + } + + //Set display to the number entered + // block errors + public void setDisplay (double value) { + if (checkError()) return; + this.displayValue=value; + + } + + //Clear the display + public void clear () { + this.displayValue=0.0; + this.errorState=false; + System.out.println("Cleared"); + } + + + //Add + public void add(double number) { + if (checkError()) return; + this.displayValue+=number; + } + + + //Subtract + public void subtract (double number) { + if (checkError()) return; + this.displayValue -= number; + } + + //Multiply + public void multiply (double number) { + if (checkError()) return; + this.displayValue *= number; + } + + //Divide + public void divide(double number) { + if (checkError()) return; + if(number ==0) { + setError(); + return; + } + this.displayValue/=number; + } + + //Caclulate the square + public void square () { + if (checkError()) return; + this.displayValue=this.displayValue*this.displayValue; + } + + //Calculate the square root + public void squareRoot() { + if (checkError()) return; + if (this.displayValue<0) { + setError(); + return; + } + this.displayValue=Math.sqrt((this.displayValue)); + } + + //Calculate the variable exponentiation + public void exponentiation(double exponent) { + if (checkError()) return; + this.displayValue=Math.pow(this.displayValue, exponent); + } + + //Calculate the inverse of the number + public void inverse() { + if (checkError()) return; + if (this.displayValue==0) { + setError(); + return; + } + this.displayValue=1/this.displayValue; + } + + //Invert the sign of the number (switch between postive and negative) + public void inverseSign() { + if (checkError()) return; + this.displayValue=-this.displayValue; + + } + + + //Check and set error + private void setError() { + this.errorState=true; + } + private boolean checkError() { + if (this.errorState) { + System.out.println("ERR"); + return true; + } + return false; + } + +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 94e8d98..7ec9faa 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -1,7 +1,122 @@ package com.zipcodewilmington.scientific_calculator; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.Before; + +import com.zipcodewilmington.scientificcalculator.CoreFeatures; + /** * Created by leon on 2/9/18. */ public class TestMainApplication { + + private CoreFeatures calculator; + + //set delta for comparisons + //assert equals (double expected, double actual, double delta) + private static final double DELTA =1e-6; + + @Before + public void setUp() { + calculator=new CoreFeatures(); + + } + + @Test + //Display initial + public void testInitialDisplay() { + assertEquals (0.0,calculator.getDisplayValue(),DELTA); + } + + @Test + //Display clear + public void testClear() { + calculator.setDisplay(100); + calculator.divide(0); + calculator.clear(); + assertEquals(0.0,calculator.getDisplayValue(),DELTA); + + } + + @Test + //Display + public void testSetDisplay (){ + calculator.setDisplay(182); + assertEquals(182,calculator.getDisplayValue(),DELTA); + + } + + @Test + //addition + public void testAdd() { + calculator.add(10); + assertEquals(10, calculator.getDisplayValue(),DELTA); + calculator.add(5); + assertEquals(15, calculator.getDisplayValue(), DELTA); + } + + @Test + //subtraction + public void testSubtract() { + calculator.setDisplay(10); + calculator.subtract(5); + assertEquals(5.0,calculator.getDisplayValue(),DELTA); + + } + + @Test + //multiplication + public void testMultiplication() { + calculator.setDisplay(5); + calculator.multiply(5); + assertEquals(25,calculator.getDisplayValue(),DELTA); + + } + + @Test + //division + public void testDivision() { + + } + + @Test + //square + public void testSquare() { + + } + + @Test + //square root + public void testRoot() { + + } + + @Test + //exponent + public void testExponent() { + + } + + @Test + //inverse + public void testInverse() { + + } + + @Test + //invert + public void testInvert() { + + } + + @Test + //display ERR + public void testError() { + + } + + + } From e4a3a8fb88001d4ca537e9c31c513f6ce7de272b Mon Sep 17 00:00:00 2001 From: jenn-182 Date: Sat, 12 Jul 2025 14:15:31 -0400 Subject: [PATCH 02/17] Added clear and Test applicaitions --- .../scientificcalculator/CoreFeatures.java | 8 +++++ .../TestMainApplication.java | 32 ++++++++++++------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java index 5c9d72a..423b755 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java @@ -35,8 +35,16 @@ public void setDisplay (double value) { //Clear the display public void clear () { + + //set display to 0 this.displayValue=0.0; this.errorState=false; + + + // Clear terminal by print lines to simulate clearing + for (int i = 0; i < 100; ++i) { + System.out.println(); + } System.out.println("Cleared"); } diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 7ec9faa..07ad6a6 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -34,7 +34,6 @@ public void testInitialDisplay() { //Display clear public void testClear() { calculator.setDisplay(100); - calculator.divide(0); calculator.clear(); assertEquals(0.0,calculator.getDisplayValue(),DELTA); @@ -78,45 +77,54 @@ public void testMultiplication() { @Test //division public void testDivision() { + calculator.setDisplay(20); + calculator.divide(5); + assertEquals(4.0,calculator.getDisplayValue(),DELTA); } @Test //square public void testSquare() { + calculator.setDisplay(5); + calculator.square(); + assertEquals(25.0,calculator.getDisplayValue(),DELTA); } @Test //square root public void testRoot() { - + calculator.setDisplay(25); + calculator.squareRoot(); + assertEquals(5.0,calculator.getDisplayValue(),DELTA); } @Test //exponent public void testExponent() { + calculator.setDisplay(3); + calculator.exponentiation(2); + assertEquals(9.0,calculator.getDisplayValue(),DELTA); } @Test //inverse public void testInverse() { + calculator.setDisplay(5); + calculator.inverse(); + assertEquals(0.20, calculator.getDisplayValue(),DELTA); } @Test - //invert - public void testInvert() { - - } - - @Test - //display ERR - public void testError() { + //invert sign + public void testInvertSign() { + calculator.setDisplay(10); + calculator.inverseSign(); + assertEquals(-10.0, calculator.getDisplayValue(),DELTA); } - - } From ab2729c40c96d422d3ea3d15b0a126767e0b627b Mon Sep 17 00:00:00 2001 From: jenn-182 Date: Sat, 12 Jul 2025 14:17:26 -0400 Subject: [PATCH 03/17] Finish --- Calc-java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Calc-java b/Calc-java index fcb06d0..cc839be 160000 --- a/Calc-java +++ b/Calc-java @@ -1 +1 @@ -Subproject commit fcb06d06ff91a20dad5d4fbbb679f47c802c6de5 +Subproject commit cc839beb411a4539b2c0fe552b43c136ad92cf61 From 09b778375b14335782201150e5255a3b319d085e Mon Sep 17 00:00:00 2001 From: jenn-182 Date: Sat, 12 Jul 2025 14:55:37 -0400 Subject: [PATCH 04/17] Added detailed comments so we can better understand each function --- .../scientificcalculator/CoreFeatures.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java index 423b755..967447a 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java @@ -5,30 +5,34 @@ public class CoreFeatures { //a state represening the value currently displayed on the calc private double displayValue; - //Update the display to ERR if an error occurs (divide by 0) + //Update the display to ERR if an error occurs (ex: divide by 0) private boolean errorState; //initiate calculator with 0 as default public CoreFeatures () { this.displayValue = 0.0; + //not an ERR this.errorState=false; } //Get the current # on the display public double getDisplayValue() { + //pull the display value return this.displayValue; } //Check for errors public boolean inErrorState() { + //pull the error state (is it true or false) return this.errorState; } //Set display to the number entered - // block errors public void setDisplay (double value) { + //(if ERR, skip the equation) if (checkError()) return; + //reset the display value to the number entered this.displayValue=value; } @@ -36,12 +40,12 @@ public void setDisplay (double value) { //Clear the display public void clear () { - //set display to 0 + //set display to 0 and remove error this.displayValue=0.0; this.errorState=false; - // Clear terminal by print lines to simulate clearing + // Clear terminal by printing lines to simulate clearing for (int i = 0; i < 100; ++i) { System.out.println(); } @@ -49,26 +53,26 @@ public void clear () { } - //Add + //Add (if ERR, skip the equation) public void add(double number) { if (checkError()) return; this.displayValue+=number; } - //Subtract + //Subtract (if ERR, skip the equation) public void subtract (double number) { if (checkError()) return; this.displayValue -= number; } - //Multiply + //Multiply (if ERR, skip the equation) public void multiply (double number) { if (checkError()) return; this.displayValue *= number; } - //Divide + //Divide (if ERR, skip the equation) public void divide(double number) { if (checkError()) return; if(number ==0) { @@ -78,13 +82,13 @@ public void divide(double number) { this.displayValue/=number; } - //Caclulate the square + //Caclulate the square (if ERR, skip the equation) public void square () { if (checkError()) return; this.displayValue=this.displayValue*this.displayValue; } - //Calculate the square root + //Calculate the square root (if ERR, skip the equation) public void squareRoot() { if (checkError()) return; if (this.displayValue<0) { @@ -94,13 +98,13 @@ public void squareRoot() { this.displayValue=Math.sqrt((this.displayValue)); } - //Calculate the variable exponentiation + //Calculate the variable exponentiation (if ERR, skip the equation) public void exponentiation(double exponent) { if (checkError()) return; this.displayValue=Math.pow(this.displayValue, exponent); } - //Calculate the inverse of the number + //Calculate the inverse of the number (if ERR, skip the equation) public void inverse() { if (checkError()) return; if (this.displayValue==0) { @@ -111,6 +115,7 @@ public void inverse() { } //Invert the sign of the number (switch between postive and negative) + //(if ERR, skip the equation) public void inverseSign() { if (checkError()) return; this.displayValue=-this.displayValue; @@ -118,10 +123,12 @@ public void inverseSign() { } - //Check and set error + //Set an error state so we can use it to compare private void setError() { this.errorState=true; } + + //check for an error before operation private boolean checkError() { if (this.errorState) { System.out.println("ERR"); From 28b43282cd0b0dcb62fdd783d09512823ecf7a1c Mon Sep 17 00:00:00 2001 From: FrankMontgomery063 Date: Sat, 12 Jul 2025 15:09:27 -0400 Subject: [PATCH 05/17] set options took user input --- .../scientificcalculator/Console.java | 15 ++- .../scientificcalculator/MainApplication.java | 115 ++++++++++++++++-- 2 files changed, 119 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 83f0e97..a5b1a48 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -17,16 +17,25 @@ public static void println(String output, Object... args) { public static String getStringInput(String prompt) { Scanner scanner = new Scanner(System.in); - println(prompt); + print(prompt); String userInput = scanner.nextLine(); + //scanner.close(); return userInput; } public static Integer getIntegerInput(String prompt) { - return null; + Scanner scanner = new Scanner(System.in); + print(prompt); + Integer userinput = scanner.nextInt(); + //scanner.close(); + return userinput; } public static Double getDoubleInput(String prompt) { - return null; + Scanner scanner = new Scanner(System.in); + print(prompt); + Double userinput = scanner.nextDouble(); + //scanner.close(); + return userinput; } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 5f42132..505051a 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -5,13 +5,112 @@ */ 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."); - - 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); + System.out.println("\nWelcome to my calculator!\n"); + + Double userinput; + Integer option=-1; + + + while(option!=19){ + userinput = Console.getDoubleInput("Enter a number: "); + showOption(); + option = Console.getIntegerInput("choose one of the options above: "); + runOption(option); + + } + + + } + + public static void showOption(){ + System.out.println("0. clear display"); + System.out.println("1. add"); + System.out.println("2. subtract"); + System.out.println("3. multiply"); + System.out.println("4. division"); + System.out.println("5. square"); + System.out.println("6. square root"); + System.out.println("7. inverse"); + System.out.println("8. switch sign"); + System.out.println("9. sine"); + System.out.println("10. cosine"); + System.out.println("11. tangent"); + System.out.println("12. inverse sine"); + System.out.println("13. inverse cosine"); + System.out.println("14. inverse tangent"); + System.out.println("15. factorial"); + System.out.println("16. switch display mode"); + System.out.println("17. switch units mode"); + System.out.println("18. memory functions"); + System.out.println("19. exit"); + } + + public static void runOption(Integer option){ + switch (option) { + case 0: + + break; + case 1: + + break; + case 2: + + break; + case 3: + + break; + case 4: + + break; + case 5: + + break; + case 6: + + break; + case 7: + + break; + case 8: + + break; + case 9: + + break; + case 10: + + break; + case 11: + + break; + case 12: + + break; + case 13: + + break; + case 14: + + break; + case 15: + + break; + case 16: + + break; + case 17: + + break; + case 18: + + break; + case 19: + + break; + + default: + + break; + } } } From fccdc9934e89a85f9dd3a1ba5c876c26e0856e6e Mon Sep 17 00:00:00 2001 From: jenn-182 Date: Sat, 12 Jul 2025 15:12:33 -0400 Subject: [PATCH 06/17] push before we leave --- Calc-java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Calc-java b/Calc-java index cc839be..09b7783 160000 --- a/Calc-java +++ b/Calc-java @@ -1 +1 @@ -Subproject commit cc839beb411a4539b2c0fe552b43c136ad92cf61 +Subproject commit 09b778375b14335782201150e5255a3b319d085e From 7af3dd9450d3f41b6938c132258937ae9b317cae Mon Sep 17 00:00:00 2001 From: FrankMontgomery063 Date: Sat, 12 Jul 2025 16:17:05 -0400 Subject: [PATCH 07/17] added switch statements and got some of the functions working --- .../scientificcalculator/MainApplication.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 505051a..9c25367 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -6,16 +6,17 @@ public class MainApplication { public static void main(String[] args) { System.out.println("\nWelcome to my calculator!\n"); - + CoreFeatures cfcalc = new CoreFeatures(); Double userinput; Integer option=-1; while(option!=19){ userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); showOption(); option = Console.getIntegerInput("choose one of the options above: "); - runOption(option); + runOption(option, cfcalc, userinput); } @@ -45,19 +46,28 @@ public static void showOption(){ System.out.println("19. exit"); } - public static void runOption(Integer option){ + public static void runOption(Integer option, CoreFeatures cfcalc, Double num){ + + Double userinput; + switch (option) { case 0: break; case 1: - + userinput = Console.getDoubleInput("Enter a number to add to "+cfcalc.getDisplayValue()+" : "); + cfcalc.add(userinput); + System.out.println("="+cfcalc.getDisplayValue()); break; case 2: - + userinput = Console.getDoubleInput("Enter a number to subtract to "+cfcalc.getDisplayValue()+" : "); + cfcalc.subtract(userinput); + System.out.println("="+cfcalc.getDisplayValue()); break; case 3: - + userinput = Console.getDoubleInput("Enter a number to multiply to "+cfcalc.getDisplayValue()+" : "); + cfcalc.multiply(userinput); + System.out.println("="+cfcalc.getDisplayValue()); break; case 4: From 0111c203bf2e6cacb44eb42bef2355f6d5f9fd7a Mon Sep 17 00:00:00 2001 From: danishahsancs Date: Sat, 12 Jul 2025 23:33:43 -0400 Subject: [PATCH 08/17] almost finished scientific methods --- .../scientificcalculator/Console.java | 1 + .../scientificcalculator/MainApplication.java | 6 + .../scientificcalculator/ScientificCalc.java | 178 ++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/ScientificCalc.java diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 83f0e97..c2f6308 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -19,6 +19,7 @@ public static String getStringInput(String prompt) { Scanner scanner = new Scanner(System.in); println(prompt); String userInput = scanner.nextLine(); + scanner.close(); return userInput; } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 5f42132..06a0ece 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -13,5 +13,11 @@ public static void main(String[] args) { 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); + + System.out.print("\033[H\033[2J"); + System.out.flush(); + + System.out.println("da\\"); + } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificCalc.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificCalc.java new file mode 100644 index 0000000..d529b15 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificCalc.java @@ -0,0 +1,178 @@ +package main.java.com.zipcodewilmington.scientificcalculator; + +public class ScientificCalc { + Double memvalue; + String DisplayMode; + int modeIndex; + boolean isDegrees; + + + public ScientificCalc(){ + memvalue = 0; + DisplayMode = "decimal"; + modeIndex = 0; + isDegrees = false; + } + + public void switchDisplayMode(){ + if(modeIndex == 3){ + modeIndex = 0; + }else{ + modeIndex++; + } + + switch (modeIndex) { + case 0: + DisplayMode = "decimal"; + break; + case 1: + DisplayMode = "hexadecimal"; + break; + case 2: + DisplayMode = "binary"; + break; + case 3: + DisplayMode = "octal"; + break; + default: + break; + } + + } + + public void switchDisplayMode(String s){ + switch (s.toLowerCase()) { + case "decimal": + modeIndex = 0; + DisplayMode = s; + break; + case "hexadecimal": + modeIndex = 1; + DisplayMode = s; + break; + case "binary": + modeIndex = 2; + DisplayMode = s; + break; + case "octal": + modeIndex = 3; + DisplayMode = s; + break; + default: + System.out.println(s + " is not valid. Setting to decimal mode\n"); + modeIndex = 0; + DisplayMode = "decimal"; + break; + } + + } + + public void memmoryFunctions(double curValue, String memoryFunction){ + switch (memoryFunction.toLowerCase()) { + case "m+": + memvalue = curValue; + break; + case "mc": + memvalue = 0; + System.out.println("memory reset\n"); + break; + case "mrc": + System.out.println("value in memory: "+memvalue); + default: + break; + } + } + + public void sine(Double x){ + if(isDegrees){ + System.out.println(Math.sin(Math.toRadians(x))); + }else{ + System.out.println(Math.sin(x)); + } + } + public void cosine(Double x){ + if(isDegrees){ + System.out.println(Math.cos(Math.toRadians(x))); + }else{ + System.out.println(Math.cos(x)); + } + } + public void tangent(Double x){ + if(isDegrees){ + System.out.println(Math.tan(Math.toRadians(x))); + }else{ + System.out.println(Math.tan(x)); + } + } + public void inverseSine(Double x){ + if(isDegrees){ + System.out.println(Math.asin(Math.toRadians(x))); + }else{ + System.out.println(Math.asin(x)); + } + } + public void inverseCosine(Double x){ + if(isDegrees){ + System.out.println(Math.acos(Math.toRadians(x))); + }else{ + System.out.println(Math.acos(x)); + } + } + public void inverseTangent(Double x){ + if(isDegrees){ + System.out.println(Math.atan(Math.toRadians(x))); + }else{ + System.out.println(Math.atan(x)); + } + } + + public void switchUnitsMode(){ + if(isDegrees){ + System.out.println("set to radians"); + isDegrees = false; + }else{ + System.out.println("set to degrees"); + isDegrees = true; + } + } + + public void switchUnitsMode(String s){ + if(s.toLowerCase() == "degree"){ + System.out.println("set to degrees"); + isDegrees = true; + }else if (s.toLowerCase() == "radians"){ + System.out.println("set to radians"); + isDegrees = false; + }else{ + System.out.println("invalid input defaulted to radians"); + isDegrees = false; + } + } + + public void log(Double x){ + System.out.println(Math.log10(x)); + } + + public void inverseLog(Double x){ + System.out.println(Math.pow(10,x)); + } + + public void naturalLog(Double x){ + System.out.println(Math.log(x)); + } + public void inverseNaturalLog(){ + System.out.println(Math.exp(x)); + } + + public void factorial(Double x){ + System.out.println(factorialFunction(x)); + } + + public Double factorialFunction(Double x){ + if(x<=1) + return 1; + + return x * factorialFunction(x-1); + } + +} From 6d62eaa517834e9d5a386933dd3d472ccaaa7fd5 Mon Sep 17 00:00:00 2001 From: FrankMontgomery063 Date: Sun, 13 Jul 2025 12:42:14 -0400 Subject: [PATCH 09/17] added, divide, up to switch sign --- .../scientificcalculator/MainApplication.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 9c25367..ab04e5d 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -70,19 +70,29 @@ public static void runOption(Integer option, CoreFeatures cfcalc, Double num){ System.out.println("="+cfcalc.getDisplayValue()); break; case 4: - + userinput = Console.getDoubleInput("Enter a number to divide to "+cfcalc.getDisplayValue()+" : "); + cfcalc.divide(userinput); + System.out.println("="+cfcalc.getDisplayValue()); break; case 5: - + userinput = Console.getDoubleInput("Enter a number to square to "+cfcalc.getDisplayValue()+" : "); + cfcalc.square(userinput); + System.out.println("="+cfcalc.getDisplayValue()+" : "); break; case 6: - + userinput = Console.getDoubleInput("Enter a number to square root to "+cfcalc.getDisplayValue()+" : "); + cfcalc.squareroot(userinput); + System.out.println("="+cfcalc.getDisplayValue()+" : "); break; case 7: - + userinput = Console.getDoubleInput("Enter a number to inverse to "+cfcalc.getDisplayValue()+" : "); + cfcalc.inverse(userinput); + System.out.println("="+cfcalc.getDisplayValue()+" : "); break; case 8: - + userinput = Console.getDoubleInput("Enter a number to switch sign to "+cfcalc.getDisplayValue()+" : "); + cfcalc.switch sign(userinput); + System.out.println("="+cfcalc.getDisplayValue()+" : "); break; case 9: From ccc3b54280e81b35564e5585275e5cc330bcdfed Mon Sep 17 00:00:00 2001 From: FrankMontgomery063 Date: Sun, 13 Jul 2025 13:04:30 -0400 Subject: [PATCH 10/17] finished function case 1-8 --- .../scientificcalculator/MainApplication.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index ab04e5d..0fd1630 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -75,23 +75,19 @@ public static void runOption(Integer option, CoreFeatures cfcalc, Double num){ System.out.println("="+cfcalc.getDisplayValue()); break; case 5: - userinput = Console.getDoubleInput("Enter a number to square to "+cfcalc.getDisplayValue()+" : "); - cfcalc.square(userinput); + cfcalc.square(); System.out.println("="+cfcalc.getDisplayValue()+" : "); break; case 6: - userinput = Console.getDoubleInput("Enter a number to square root to "+cfcalc.getDisplayValue()+" : "); - cfcalc.squareroot(userinput); + cfcalc.squareRoot(); System.out.println("="+cfcalc.getDisplayValue()+" : "); break; case 7: - userinput = Console.getDoubleInput("Enter a number to inverse to "+cfcalc.getDisplayValue()+" : "); - cfcalc.inverse(userinput); + cfcalc.inverse(); System.out.println("="+cfcalc.getDisplayValue()+" : "); break; case 8: - userinput = Console.getDoubleInput("Enter a number to switch sign to "+cfcalc.getDisplayValue()+" : "); - cfcalc.switch sign(userinput); + cfcalc.inverseSign(); System.out.println("="+cfcalc.getDisplayValue()+" : "); break; case 9: From 9e4098074a916091d667dd2a8b8cd060c2a49a26 Mon Sep 17 00:00:00 2001 From: danishahsancs Date: Sun, 13 Jul 2025 13:20:18 -0400 Subject: [PATCH 11/17] finished cases 8-18 --- .../scientificcalculator/MainApplication.java | 93 ++++++++++++++---- .../scientificcalculator/ScientificCalc.java | 94 +++++++++++-------- 2 files changed, 128 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 9c25367..e275d97 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -7,6 +7,7 @@ public class MainApplication { public static void main(String[] args) { System.out.println("\nWelcome to my calculator!\n"); CoreFeatures cfcalc = new CoreFeatures(); + ScientificCalc sCalc = new ScientificCalc(); Double userinput; Integer option=-1; @@ -16,7 +17,7 @@ public static void main(String[] args) { cfcalc.setDisplay(userinput); showOption(); option = Console.getIntegerInput("choose one of the options above: "); - runOption(option, cfcalc, userinput); + runOption(option, cfcalc, sCalc,userinput); } @@ -46,18 +47,52 @@ public static void showOption(){ System.out.println("19. exit"); } - public static void runOption(Integer option, CoreFeatures cfcalc, Double num){ + public static String outputConverter(ScientificCalc sCalc, Double x){ + String temp = ""; + int aperiod; + int bperiod; + String parts[]; + + switch (sCalc.getDisplayMode()) { + case "decimal": + temp = String.valueOf(x); + break; + case "hexadecimal": + temp = Double.toHexString(x); + break; + case "binary": + parts = String.valueOf(x).split("\\.") ; + bperiod = Integer.valueOf(parts[0]); + aperiod = Integer.valueOf(parts[1]); + temp = Integer.toBinaryString(bperiod)+"."+Integer.toBinaryString(aperiod); + break; + case "octal": + parts = String.valueOf(x).split("\\.") ; + bperiod = Integer.valueOf(parts[0]); + aperiod = Integer.valueOf(parts[1]); + temp = Integer.toOctalString(bperiod)+"."+Integer.toOctalString(aperiod); + break; + default: + + break; + } + + + return temp; + } + + public static void runOption(Integer option, CoreFeatures cfcalc,ScientificCalc sCalc ,Double num){ Double userinput; switch (option) { case 0: - + cfcalc.clear(); break; case 1: userinput = Console.getDoubleInput("Enter a number to add to "+cfcalc.getDisplayValue()+" : "); cfcalc.add(userinput); - System.out.println("="+cfcalc.getDisplayValue()); + System.out.println("="+outputConverter(sCalc, cfcalc.getDisplayValue())); break; case 2: userinput = Console.getDoubleInput("Enter a number to subtract to "+cfcalc.getDisplayValue()+" : "); @@ -85,39 +120,61 @@ public static void runOption(Integer option, CoreFeatures cfcalc, Double num){ break; case 9: - + System.out.println("sine("+cfcalc.getDisplayValue()+")= "+outputConverter(sCalc, sCalc.sine(cfcalc.getDisplayValue()))); break; case 10: - + System.out.println("cosine("+cfcalc.getDisplayValue()+")= "+outputConverter(sCalc, sCalc.cosine(cfcalc.getDisplayValue()))); break; case 11: - + System.out.println("tangent("+cfcalc.getDisplayValue()+")= "+outputConverter(sCalc, sCalc.tangent(cfcalc.getDisplayValue()))); break; case 12: - + System.out.println("inverse sine("+cfcalc.getDisplayValue()+")= "+outputConverter(sCalc, sCalc.inverseSine(cfcalc.getDisplayValue()))); break; case 13: - + System.out.println("inverse cosine("+cfcalc.getDisplayValue()+")= "+outputConverter(sCalc, sCalc.inverseCosine(cfcalc.getDisplayValue()))); break; case 14: - + System.out.println("inverse tangent("+cfcalc.getDisplayValue()+")= "+outputConverter(sCalc, sCalc.inverseTangent(cfcalc.getDisplayValue()))); break; case 15: - + System.out.println("factorial("+cfcalc.getDisplayValue()+")= "+outputConverter(sCalc, sCalc.factorial(cfcalc.getDisplayValue()))); break; case 16: + String temp = ""; + temp = Console.getStringInput("type an option or click enter for auto next (decimal, hexadecimal, binary, octal): "); + if(temp.isEmpty()) + sCalc.switchDisplayMode(); + else + sCalc.switchDisplayMode(temp); break; case 17: - + String temp2 = ""; + temp2 = Console.getStringInput("type an option or click enter for auto next (radians, degree): "); + if(temp2.isEmpty()) + sCalc.switchUnitsMode(); + else + sCalc.switchUnitsMode(temp2); break; case 18: - - break; - case 19: - - break; - + int x = Console.getIntegerInput("Memmory options:\n1.Add a number to memmory\n2.Reset memmory\n3.Recall for memmory\nChoose an option: "); + switch (x) { + case 1: + userinput = Console.getDoubleInput("Enter an number to add to memory: "); + sCalc.memmoryFunctions(x, "m+"); + break; + case 2: + sCalc.memmoryFunctions(x, "mc"); + break; + case 3: + sCalc.memmoryFunctions(x, "mrc"); + cfcalc.setDisplay(sCalc.mrc()); + break; + default: + break; + } + break; default: break; diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificCalc.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificCalc.java index d529b15..89a6217 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificCalc.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificCalc.java @@ -1,4 +1,4 @@ -package main.java.com.zipcodewilmington.scientificcalculator; +package com.zipcodewilmington.scientificcalculator; public class ScientificCalc { Double memvalue; @@ -8,7 +8,7 @@ public class ScientificCalc { public ScientificCalc(){ - memvalue = 0; + memvalue = 0.0; DisplayMode = "decimal"; modeIndex = 0; isDegrees = false; @@ -24,15 +24,19 @@ public void switchDisplayMode(){ switch (modeIndex) { case 0: DisplayMode = "decimal"; + System.out.println("set to:" + DisplayMode); break; case 1: DisplayMode = "hexadecimal"; + System.out.println("set to:" + DisplayMode); break; case 2: DisplayMode = "binary"; + System.out.println("set to:" + DisplayMode); break; case 3: DisplayMode = "octal"; + System.out.println("set to:" + DisplayMode); break; default: break; @@ -40,6 +44,10 @@ public void switchDisplayMode(){ } + public String getDisplayMode(){ + return DisplayMode; + } + public void switchDisplayMode(String s){ switch (s.toLowerCase()) { case "decimal": @@ -73,7 +81,7 @@ public void memmoryFunctions(double curValue, String memoryFunction){ memvalue = curValue; break; case "mc": - memvalue = 0; + memvalue = 0.0; System.out.println("memory reset\n"); break; case "mrc": @@ -83,48 +91,52 @@ public void memmoryFunctions(double curValue, String memoryFunction){ } } - public void sine(Double x){ + public Double mrc(){ + return memvalue; + } + + public double sine(Double x){ if(isDegrees){ - System.out.println(Math.sin(Math.toRadians(x))); + return Math.sin(Math.toRadians(x)); }else{ - System.out.println(Math.sin(x)); + return Math.sin(x); } } - public void cosine(Double x){ + public double cosine(Double x){ if(isDegrees){ - System.out.println(Math.cos(Math.toRadians(x))); + return Math.cos(Math.toRadians(x)); }else{ - System.out.println(Math.cos(x)); + return Math.cos(x); } } - public void tangent(Double x){ + public double tangent(Double x){ if(isDegrees){ - System.out.println(Math.tan(Math.toRadians(x))); + return Math.tan(Math.toRadians(x)); }else{ - System.out.println(Math.tan(x)); + return Math.tan(x); } } - public void inverseSine(Double x){ - if(isDegrees){ - System.out.println(Math.asin(Math.toRadians(x))); - }else{ - System.out.println(Math.asin(x)); - } + public double inverseSine(Double x){ + if(isDegrees){ + return Math.toDegrees(Math.asin(x)); + }else{ + return Math.asin(x); } - public void inverseCosine(Double x){ - if(isDegrees){ - System.out.println(Math.acos(Math.toRadians(x))); - }else{ - System.out.println(Math.acos(x)); - } +} +public double inverseCosine(Double x){ + if(isDegrees){ + return Math.toDegrees(Math.acos(x)); + }else{ + return Math.acos(x); } - public void inverseTangent(Double x){ - if(isDegrees){ - System.out.println(Math.atan(Math.toRadians(x))); - }else{ - System.out.println(Math.atan(x)); - } +} +public double inverseTangent(Double x){ + if(isDegrees){ + return Math.toDegrees(Math.atan(x)); + }else{ + return Math.atan(x); } +} public void switchUnitsMode(){ if(isDegrees){ @@ -149,28 +161,28 @@ public void switchUnitsMode(String s){ } } - public void log(Double x){ - System.out.println(Math.log10(x)); + public double log(Double x){ + return Math.log10(x); } - public void inverseLog(Double x){ - System.out.println(Math.pow(10,x)); + public double inverseLog(Double x){ + return Math.pow(10,x); } - public void naturalLog(Double x){ - System.out.println(Math.log(x)); + public double naturalLog(Double x){ + return Math.log(x); } - public void inverseNaturalLog(){ - System.out.println(Math.exp(x)); + public double inverseNaturalLog(Double x){ + return Math.exp(x); } - public void factorial(Double x){ - System.out.println(factorialFunction(x)); + public double factorial(Double x){ + return factorialFunction(x); } public Double factorialFunction(Double x){ if(x<=1) - return 1; + return 1.0; return x * factorialFunction(x-1); } From 0aac3344f395a1232d2a8aee91ce9f918256da37 Mon Sep 17 00:00:00 2001 From: jenn-182 Date: Sun, 13 Jul 2025 13:24:19 -0400 Subject: [PATCH 12/17] Added new features and fixed core --- Calc-java | 2 +- .../scientificcalculator/CoreFeatures.java | 15 +++++++++++++++ .../scientificcalculator/MainApplication.java | 8 ++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Calc-java b/Calc-java index 09b7783..a03f172 160000 --- a/Calc-java +++ b/Calc-java @@ -1 +1 @@ -Subproject commit 09b778375b14335782201150e5255a3b319d085e +Subproject commit a03f1721eda47ee8c0a0ea3aa473529516156a5c diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java index 967447a..6d9f3a9 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java @@ -114,6 +114,20 @@ public void inverse() { this.displayValue=1/this.displayValue; } + //Caclulate the percentage of another number NEW FEATURE #1 + public void percentage(double percent) { + if (checkError()) return; + this.displayValue = (percent/100)*this.displayValue; + + } + + //Takes a decimal and returns the percentage NEW FEATURE #2 + public void decimalToPercentage () { + if (checkError()) return; + this.displayValue*=100; + + } + //Invert the sign of the number (switch between postive and negative) //(if ERR, skip the equation) public void inverseSign() { @@ -137,4 +151,5 @@ private boolean checkError() { return false; } + } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index ab04e5d..ffa45bb 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -76,22 +76,22 @@ public static void runOption(Integer option, CoreFeatures cfcalc, Double num){ break; case 5: userinput = Console.getDoubleInput("Enter a number to square to "+cfcalc.getDisplayValue()+" : "); - cfcalc.square(userinput); + cfcalc.square(); System.out.println("="+cfcalc.getDisplayValue()+" : "); break; case 6: userinput = Console.getDoubleInput("Enter a number to square root to "+cfcalc.getDisplayValue()+" : "); - cfcalc.squareroot(userinput); + cfcalc.squareRoot(); System.out.println("="+cfcalc.getDisplayValue()+" : "); break; case 7: userinput = Console.getDoubleInput("Enter a number to inverse to "+cfcalc.getDisplayValue()+" : "); - cfcalc.inverse(userinput); + cfcalc.inverse(); System.out.println("="+cfcalc.getDisplayValue()+" : "); break; case 8: userinput = Console.getDoubleInput("Enter a number to switch sign to "+cfcalc.getDisplayValue()+" : "); - cfcalc.switch sign(userinput); + cfcalc.inverseSign(); System.out.println("="+cfcalc.getDisplayValue()+" : "); break; case 9: From d94a738dd9f2b56b8bc907739670a0391c30ab29 Mon Sep 17 00:00:00 2001 From: jenn-182 Date: Sun, 13 Jul 2025 13:42:26 -0400 Subject: [PATCH 13/17] New features test applications --- Calc-java | 2 +- .../TestMainApplication.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Calc-java b/Calc-java index a03f172..7541278 160000 --- a/Calc-java +++ b/Calc-java @@ -1 +1 @@ -Subproject commit a03f1721eda47ee8c0a0ea3aa473529516156a5c +Subproject commit 75412788571561ae4fdda36d383f2ed50a5f3f86 diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 07ad6a6..bd127dd 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -126,5 +126,20 @@ public void testInvertSign() { assertEquals(-10.0, calculator.getDisplayValue(),DELTA); } + @Test + //new feature percentage of a number + public void testPercentageOfNum() { + calculator.setDisplay(100); + calculator.percentage(50); + assertEquals(50.0, calculator.getDisplayValue(), DELTA); + } + + @Test + //new feature turn decimal into a percentage + public void testDecimalToPercent() { + calculator.setDisplay(0.50); + calculator.decimalToPercentage(); + assertEquals(50.0, calculator.getDisplayValue(),DELTA); + } } From c6556017339448cf711f5011902b12329f37fff9 Mon Sep 17 00:00:00 2001 From: danishahsancs Date: Sun, 13 Jul 2025 14:00:16 -0400 Subject: [PATCH 14/17] fixed memmory recall and implemened converter onto franks code --- .../scientificcalculator/MainApplication.java | 150 +++++++++++++----- 1 file changed, 108 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 9a77712..b9da496 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -8,23 +8,18 @@ public static void main(String[] args) { System.out.println("\nWelcome to my calculator!\n"); CoreFeatures cfcalc = new CoreFeatures(); ScientificCalc sCalc = new ScientificCalc(); - Double userinput; - Integer option=-1; - + Integer option = -1; - while(option!=19){ - userinput = Console.getDoubleInput("Enter a number: "); - cfcalc.setDisplay(userinput); + while (option != 19) { showOption(); option = Console.getIntegerInput("choose one of the options above: "); - runOption(option, cfcalc, sCalc,userinput); + runOption(option, cfcalc, sCalc); } - } - public static void showOption(){ + public static void showOption() { System.out.println("0. clear display"); System.out.println("1. add"); System.out.println("2. subtract"); @@ -47,7 +42,7 @@ public static void showOption(){ System.out.println("19. exit"); } - public static String outputConverter(ScientificCalc sCalc, Double x){ + public static String outputConverter(ScientificCalc sCalc, Double x) { String temp = ""; int aperiod; int bperiod; @@ -61,114 +56,185 @@ public static String outputConverter(ScientificCalc sCalc, Double x){ temp = Double.toHexString(x); break; case "binary": - parts = String.valueOf(x).split("\\.") ; + parts = String.valueOf(x).split("\\."); bperiod = Integer.valueOf(parts[0]); aperiod = Integer.valueOf(parts[1]); - temp = Integer.toBinaryString(bperiod)+"."+Integer.toBinaryString(aperiod); + temp = Integer.toBinaryString(bperiod) + "." + Integer.toBinaryString(aperiod); break; case "octal": - parts = String.valueOf(x).split("\\.") ; + parts = String.valueOf(x).split("\\."); bperiod = Integer.valueOf(parts[0]); aperiod = Integer.valueOf(parts[1]); - temp = Integer.toOctalString(bperiod)+"."+Integer.toOctalString(aperiod); + temp = Integer.toOctalString(bperiod) + "." + Integer.toOctalString(aperiod); break; default: break; } - return temp; } - public static void runOption(Integer option, CoreFeatures cfcalc,ScientificCalc sCalc ,Double num){ + public static void runOption(Integer option, CoreFeatures cfcalc, ScientificCalc sCalc) { Double userinput; + boolean isdiplayval = cfcalc.getDisplayValue() != 0.0; + switch (option) { case 0: cfcalc.clear(); + cfcalc.setDisplay(0.0); break; case 1: - userinput = Console.getDoubleInput("Enter a number to add to "+cfcalc.getDisplayValue()+" : "); + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } + userinput = Console.getDoubleInput("Enter a number to add to " + cfcalc.getDisplayValue() + " : "); cfcalc.add(userinput); - System.out.println("="+outputConverter(sCalc, cfcalc.getDisplayValue())); + System.out.println("=" + outputConverter(sCalc, cfcalc.getDisplayValue())); break; case 2: - userinput = Console.getDoubleInput("Enter a number to subtract to "+cfcalc.getDisplayValue()+" : "); + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } + userinput = Console.getDoubleInput("Enter a number to subtract to " + cfcalc.getDisplayValue() + " : "); cfcalc.subtract(userinput); - System.out.println("="+cfcalc.getDisplayValue()); + System.out.println("=" + outputConverter(sCalc, cfcalc.getDisplayValue())); break; case 3: - userinput = Console.getDoubleInput("Enter a number to multiply to "+cfcalc.getDisplayValue()+" : "); + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } + userinput = Console.getDoubleInput("Enter a number to multiply to " + cfcalc.getDisplayValue() + " : "); cfcalc.multiply(userinput); - System.out.println("="+cfcalc.getDisplayValue()); + System.out.println("=" + outputConverter(sCalc, cfcalc.getDisplayValue())); break; case 4: - userinput = Console.getDoubleInput("Enter a number to divide to "+cfcalc.getDisplayValue()+" : "); + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } + userinput = Console.getDoubleInput("Enter a number to divide to " + cfcalc.getDisplayValue() + " : "); cfcalc.divide(userinput); - System.out.println("="+cfcalc.getDisplayValue()); + System.out.println("=" + outputConverter(sCalc, cfcalc.getDisplayValue())); break; case 5: + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } cfcalc.square(); - System.out.println("="+cfcalc.getDisplayValue()+" : "); + System.out.println("=" + outputConverter(sCalc, cfcalc.getDisplayValue())); break; case 6: + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } cfcalc.squareRoot(); - System.out.println("="+cfcalc.getDisplayValue()+" : "); + System.out.println("=" + outputConverter(sCalc, cfcalc.getDisplayValue())); break; case 7: + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } cfcalc.inverse(); - System.out.println("="+cfcalc.getDisplayValue()+" : "); + System.out.println("=" + outputConverter(sCalc, cfcalc.getDisplayValue())); break; case 8: + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } cfcalc.inverseSign(); - System.out.println("="+cfcalc.getDisplayValue()+" : "); + System.out.println("=" + outputConverter(sCalc, cfcalc.getDisplayValue())); break; case 9: - System.out.println("sine("+cfcalc.getDisplayValue()+")= "+outputConverter(sCalc, sCalc.sine(cfcalc.getDisplayValue()))); + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } + System.out.println("sine(" + cfcalc.getDisplayValue() + ")= " + + outputConverter(sCalc, sCalc.sine(cfcalc.getDisplayValue()))); break; case 10: - System.out.println("cosine("+cfcalc.getDisplayValue()+")= "+outputConverter(sCalc, sCalc.cosine(cfcalc.getDisplayValue()))); + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } + System.out.println("cosine(" + cfcalc.getDisplayValue() + ")= " + + outputConverter(sCalc, sCalc.cosine(cfcalc.getDisplayValue()))); break; case 11: - System.out.println("tangent("+cfcalc.getDisplayValue()+")= "+outputConverter(sCalc, sCalc.tangent(cfcalc.getDisplayValue()))); + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } + System.out.println("tangent(" + cfcalc.getDisplayValue() + ")= " + + outputConverter(sCalc, sCalc.tangent(cfcalc.getDisplayValue()))); break; case 12: - System.out.println("inverse sine("+cfcalc.getDisplayValue()+")= "+outputConverter(sCalc, sCalc.inverseSine(cfcalc.getDisplayValue()))); + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } + System.out.println("inverse sine(" + cfcalc.getDisplayValue() + ")= " + + outputConverter(sCalc, sCalc.inverseSine(cfcalc.getDisplayValue()))); break; case 13: - System.out.println("inverse cosine("+cfcalc.getDisplayValue()+")= "+outputConverter(sCalc, sCalc.inverseCosine(cfcalc.getDisplayValue()))); + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } + System.out.println("inverse cosine(" + cfcalc.getDisplayValue() + ")= " + + outputConverter(sCalc, sCalc.inverseCosine(cfcalc.getDisplayValue()))); break; case 14: - System.out.println("inverse tangent("+cfcalc.getDisplayValue()+")= "+outputConverter(sCalc, sCalc.inverseTangent(cfcalc.getDisplayValue()))); + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } + System.out.println("inverse tangent(" + cfcalc.getDisplayValue() + ")= " + + outputConverter(sCalc, sCalc.inverseTangent(cfcalc.getDisplayValue()))); break; case 15: - System.out.println("factorial("+cfcalc.getDisplayValue()+")= "+outputConverter(sCalc, sCalc.factorial(cfcalc.getDisplayValue()))); + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } + System.out.println("factorial(" + cfcalc.getDisplayValue() + ")= " + + outputConverter(sCalc, sCalc.factorial(cfcalc.getDisplayValue()))); break; case 16: String temp = ""; - temp = Console.getStringInput("type an option or click enter for auto next (decimal, hexadecimal, binary, octal): "); - if(temp.isEmpty()) + temp = Console.getStringInput( + "type an option or click enter for auto next (decimal, hexadecimal, binary, octal): "); + if (temp.isEmpty()) sCalc.switchDisplayMode(); else sCalc.switchDisplayMode(temp); - + break; case 17: String temp2 = ""; temp2 = Console.getStringInput("type an option or click enter for auto next (radians, degree): "); - if(temp2.isEmpty()) + if (temp2.isEmpty()) sCalc.switchUnitsMode(); else sCalc.switchUnitsMode(temp2); break; case 18: - int x = Console.getIntegerInput("Memmory options:\n1.Add a number to memmory\n2.Reset memmory\n3.Recall for memmory\nChoose an option: "); + int x = Console.getIntegerInput( + "Memmory options:\n1.Add a number to memmory\n2.Reset memmory\n3.Recall from memmory\nChoose an option: "); switch (x) { case 1: userinput = Console.getDoubleInput("Enter an number to add to memory: "); - sCalc.memmoryFunctions(x, "m+"); + sCalc.memmoryFunctions(userinput, "m+"); break; case 2: sCalc.memmoryFunctions(x, "mc"); @@ -180,7 +246,7 @@ public static void runOption(Integer option, CoreFeatures cfcalc,ScientificCalc default: break; } - break; + break; default: break; From ef86da594572d0774938761ebfeeff1f581445e7 Mon Sep 17 00:00:00 2001 From: jenn-182 Date: Sun, 13 Jul 2025 14:06:25 -0400 Subject: [PATCH 15/17] finished --- Calc-java | 2 +- .../zipcodewilmington/scientificcalculator/CoreFeatures.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Calc-java b/Calc-java index 7541278..0ef3432 160000 --- a/Calc-java +++ b/Calc-java @@ -1 +1 @@ -Subproject commit 75412788571561ae4fdda36d383f2ed50a5f3f86 +Subproject commit 0ef3432b02c28920fe3eed9f1c83d0ef1c136fe8 diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java index 6d9f3a9..2d9befb 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java @@ -46,7 +46,7 @@ public void clear () { // Clear terminal by printing lines to simulate clearing - for (int i = 0; i < 100; ++i) { + for (int i = 0; i < 50; ++i) { System.out.println(); } System.out.println("Cleared"); From c0d60937796574c87b0a31f74ac04fe68abe60d8 Mon Sep 17 00:00:00 2001 From: danishahsancs Date: Sun, 13 Jul 2025 14:33:07 -0400 Subject: [PATCH 16/17] fixed sum bugs --- .../scientificcalculator/CoreFeatures.java | 2 +- .../scientificcalculator/MainApplication.java | 65 ++++++++++++------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java index 6d9f3a9..98c6301 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java @@ -117,7 +117,7 @@ public void inverse() { //Caclulate the percentage of another number NEW FEATURE #1 public void percentage(double percent) { if (checkError()) return; - this.displayValue = (percent/100)*this.displayValue; + this.displayValue = (percent)*this.displayValue; } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index b9da496..e0a3795 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -10,26 +10,27 @@ public static void main(String[] args) { ScientificCalc sCalc = new ScientificCalc(); Integer option = -1; - while (option != 19) { + while (option != 21) { showOption(); option = Console.getIntegerInput("choose one of the options above: "); runOption(option, cfcalc, sCalc); + System.out.println("\n"); } } public static void showOption() { - System.out.println("0. clear display"); - System.out.println("1. add"); - System.out.println("2. subtract"); - System.out.println("3. multiply"); - System.out.println("4. division"); - System.out.println("5. square"); - System.out.println("6. square root"); - System.out.println("7. inverse"); - System.out.println("8. switch sign"); - System.out.println("9. sine"); + System.out.println("0. clear display"); + System.out.println("1. add"); + System.out.println("2. subtract"); + System.out.println("3. multiply"); + System.out.println("4. division"); + System.out.println("5. square"); + System.out.println("6. square root"); + System.out.println("7. inverse"); + System.out.println("8. switch sign"); + System.out.println("9. sine"); System.out.println("10. cosine"); System.out.println("11. tangent"); System.out.println("12. inverse sine"); @@ -39,7 +40,9 @@ public static void showOption() { System.out.println("16. switch display mode"); System.out.println("17. switch units mode"); System.out.println("18. memory functions"); - System.out.println("19. exit"); + System.out.println("19. calculate percent of number"); + System.out.println("20. decimal to percent"); + System.out.println("21. exit"); } public static String outputConverter(ScientificCalc sCalc, Double x) { @@ -124,7 +127,7 @@ public static void runOption(Integer option, CoreFeatures cfcalc, ScientificCalc break; case 5: if (!isdiplayval) { - userinput = Console.getDoubleInput("Enter a number: "); + userinput = Console.getDoubleInput("Enter a number to square: "); cfcalc.setDisplay(userinput); } cfcalc.square(); @@ -132,7 +135,7 @@ public static void runOption(Integer option, CoreFeatures cfcalc, ScientificCalc break; case 6: if (!isdiplayval) { - userinput = Console.getDoubleInput("Enter a number: "); + userinput = Console.getDoubleInput("Enter a number to sqaure root: "); cfcalc.setDisplay(userinput); } cfcalc.squareRoot(); @@ -140,7 +143,7 @@ public static void runOption(Integer option, CoreFeatures cfcalc, ScientificCalc break; case 7: if (!isdiplayval) { - userinput = Console.getDoubleInput("Enter a number: "); + userinput = Console.getDoubleInput("Enter a number enter a numebr to inverse: "); cfcalc.setDisplay(userinput); } cfcalc.inverse(); @@ -148,7 +151,7 @@ public static void runOption(Integer option, CoreFeatures cfcalc, ScientificCalc break; case 8: if (!isdiplayval) { - userinput = Console.getDoubleInput("Enter a number: "); + userinput = Console.getDoubleInput("Enter a number enter a number to switch sign: "); cfcalc.setDisplay(userinput); } cfcalc.inverseSign(); @@ -156,7 +159,7 @@ public static void runOption(Integer option, CoreFeatures cfcalc, ScientificCalc break; case 9: if (!isdiplayval) { - userinput = Console.getDoubleInput("Enter a number: "); + userinput = Console.getDoubleInput("Enter a number to get sine of: "); cfcalc.setDisplay(userinput); } System.out.println("sine(" + cfcalc.getDisplayValue() + ")= " @@ -164,7 +167,7 @@ public static void runOption(Integer option, CoreFeatures cfcalc, ScientificCalc break; case 10: if (!isdiplayval) { - userinput = Console.getDoubleInput("Enter a number: "); + userinput = Console.getDoubleInput("Enter a number to get cosine of: "); cfcalc.setDisplay(userinput); } System.out.println("cosine(" + cfcalc.getDisplayValue() + ")= " @@ -172,7 +175,7 @@ public static void runOption(Integer option, CoreFeatures cfcalc, ScientificCalc break; case 11: if (!isdiplayval) { - userinput = Console.getDoubleInput("Enter a number: "); + userinput = Console.getDoubleInput("Enter a number to get tangent of: "); cfcalc.setDisplay(userinput); } System.out.println("tangent(" + cfcalc.getDisplayValue() + ")= " @@ -180,7 +183,7 @@ public static void runOption(Integer option, CoreFeatures cfcalc, ScientificCalc break; case 12: if (!isdiplayval) { - userinput = Console.getDoubleInput("Enter a number: "); + userinput = Console.getDoubleInput("Enter a number to get inverse sine of: "); cfcalc.setDisplay(userinput); } System.out.println("inverse sine(" + cfcalc.getDisplayValue() + ")= " @@ -188,7 +191,7 @@ public static void runOption(Integer option, CoreFeatures cfcalc, ScientificCalc break; case 13: if (!isdiplayval) { - userinput = Console.getDoubleInput("Enter a number: "); + userinput = Console.getDoubleInput("Enter a number to get inverse cosine of: "); cfcalc.setDisplay(userinput); } System.out.println("inverse cosine(" + cfcalc.getDisplayValue() + ")= " @@ -196,7 +199,7 @@ public static void runOption(Integer option, CoreFeatures cfcalc, ScientificCalc break; case 14: if (!isdiplayval) { - userinput = Console.getDoubleInput("Enter a number: "); + userinput = Console.getDoubleInput("Enter a number: enter a number to get inverse tangent of "); cfcalc.setDisplay(userinput); } System.out.println("inverse tangent(" + cfcalc.getDisplayValue() + ")= " @@ -204,7 +207,7 @@ public static void runOption(Integer option, CoreFeatures cfcalc, ScientificCalc break; case 15: if (!isdiplayval) { - userinput = Console.getDoubleInput("Enter a number: "); + userinput = Console.getDoubleInput("Enter a number to do factorial on: "); cfcalc.setDisplay(userinput); } System.out.println("factorial(" + cfcalc.getDisplayValue() + ")= " @@ -247,6 +250,22 @@ public static void runOption(Integer option, CoreFeatures cfcalc, ScientificCalc break; } break; + case 19: + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a number: "); + cfcalc.setDisplay(userinput); + } + userinput = Console.getDoubleInput("Enter a number to see what percent of " + cfcalc.getDisplayValue() + " it is : "); + cfcalc.percentage(userinput); + System.out.println("= "+ cfcalc.getDisplayValue()+"%"); + + case 20: + if (!isdiplayval) { + userinput = Console.getDoubleInput("Enter a decimal to turn to percent: "); + cfcalc.setDisplay(userinput); + } + cfcalc.decimalToPercentage(); + System.out.println("= "+ cfcalc.getDisplayValue()+"%"); default: break; From f3b1d10fa0a0b3ea9791a37e614fe38b5833bac5 Mon Sep 17 00:00:00 2001 From: danishahsancs Date: Sun, 13 Jul 2025 14:39:28 -0400 Subject: [PATCH 17/17] fixed percent issue --- .../zipcodewilmington/scientificcalculator/CoreFeatures.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java index 91686d8..2c73fe7 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java @@ -117,7 +117,7 @@ public void inverse() { //Caclulate the percentage of another number NEW FEATURE #1 public void percentage(double percent) { if (checkError()) return; - this.displayValue = (percent)*this.displayValue; + this.displayValue = (percent/this.displayValue)*100; }