From de096138510205a2cd20f1f2b2d2257071e03598 Mon Sep 17 00:00:00 2001 From: Giles Bradford Date: Fri, 7 Feb 2020 16:17:56 -0500 Subject: [PATCH 01/29] adding branches --- .DS_Store | Bin 0 -> 6148 bytes src/.DS_Store | Bin 0 -> 6148 bytes src/main/.DS_Store | Bin 0 -> 6148 bytes src/main/java/.DS_Store | Bin 0 -> 6148 bytes .../scientificcalculator/CoreFunctions.java | 6 ++++++ .../ScientificFunctions.java | 4 ++++ src/test/.DS_Store | Bin 0 -> 6148 bytes src/test/java/.DS_Store | Bin 0 -> 6148 bytes .../scientific_calculator/CoreFunctionsTest.java | 4 ++++ .../ScientificFunctionsTest.java | 4 ++++ 10 files changed, 18 insertions(+) create mode 100644 .DS_Store create mode 100644 src/.DS_Store create mode 100644 src/main/.DS_Store create mode 100644 src/main/java/.DS_Store create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java create mode 100644 src/test/.DS_Store create mode 100644 src/test/java/.DS_Store create mode 100644 src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java create mode 100644 src/test/java/com/zipcodewilmington/scientific_calculator/ScientificFunctionsTest.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9a874b5768f336915163bb88cd434575b859f936 GIT binary patch literal 6148 zcmeH~Jr2S!425ml0g0s}V-^m;4I%_5-~tF3k&vj^b9A16778<}(6eNJu~Vz<8=6`~ zboab&MFtUB!i}=AFfm2m$tVxGT*u4pe81nUlA49C} z?O@64YO)2RT{MRe%{!}2F))pG(Sih~)xkgosK7*lF7m<7{{#Hn{6A@7N(HFEpDCdI z{3 z&ZCzgHV+Vc;h4w>&5}w?s#S|&NoTxOUN0OIlMaiUc~0GI)uCA2&UlM-SWna_1*E{G z0=Kzbdi{T-&-DM7B(0=?6!=pL*s$KLSA0^{*2&|%);9VR-E)5EZkz{&LzH7;lw&Tu f9N$M$<~5&lzZZ^)L1#SZMEwl7E;1?b+X|cjR1+BX literal 0 HcmV?d00001 diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..55c1fcbeb4ba2bef02771ea2748f3e4b0ea5c07d GIT binary patch literal 6148 zcmeH~J&wXa427SU6iC~oq@0EW>)m< zk%er^j=Knh3!DIf); zz>E~gV|@8Jqi52iNC7D@4+Z@DQ0UH@Y@PAxV2BZb99RzHI%Wy7c!8|R*2xOZa(b|A zwHQOZ9_?hw>uR!f_I6kfAC`AEpJHg%+hK(X&1yhF3P^#80*juHe*W+1ujcQ^n8@Auu4PPqH)~DC=`aY|^Zges(XZZ6Iz{HQ@6+Mjm#TR5vwoX=P`Vj~j6r{kv GD)0dNyb`AX literal 0 HcmV?d00001 diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..35a54bf0595027f28217af82c3d32981e121b5e7 GIT binary patch literal 6148 zcmeH~Jr2S!425mVP>H1@V-^m;4I%_5-~tF3K^+i#j?VMXLSaS~dY0@jc51bKLsN^0 z?w;4J$RHv;+$b9h6I0}!Tx68{^>MkK$MI$*w?)zl@IfZ~xlK?3DnJFO02QDDGg2TA z@_sd=XX2w!0V*&L1?>A!;KrJ4LH~3h_y_tMAK>5S|49o|DnJGPOaWc) zkNX{7D$mxB*R%R5tF~@%&@V@L`w2i|NAVi&hW%m-uqIm&6&Qa6Tm}Xz@KXg|*oF~o literal 0 HcmV?d00001 diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java new file mode 100644 index 00000000..ed989149 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java @@ -0,0 +1,6 @@ +package com.zipcodewilmington.scientificcalculator; + +public class CoreFunctions { + + public +} diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java new file mode 100644 index 00000000..41356844 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -0,0 +1,4 @@ +package com.zipcodewilmington.scientificcalculator; + +public class ScientificFunctions { +} diff --git a/src/test/.DS_Store b/src/test/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..55c1fcbeb4ba2bef02771ea2748f3e4b0ea5c07d GIT binary patch literal 6148 zcmeH~J&wXa427SU6iC~oq@0EW>)m< zk%er^j=Knh3!DIf); zz>E~gV|@8Jqi52iNC7D@4+Z@DQ0UH@Y@PAxV2BZb99RzHI%Wy7c!8|R*2xOZa(b|A zwHQOZ9_?hw>uR!f_I6kfAC`AEpJHg%+hK(X&1yhF3P^#80*juHe*W+1ujcQ^n8@Auu4PPqH)~DC=`aY|^Zges(XZZ6Iz{HQ@6+Mjm#TR5vwoX=P`Vj~j6r{kv GD)0dNyb`AX literal 0 HcmV?d00001 diff --git a/src/test/java/.DS_Store b/src/test/java/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..35a54bf0595027f28217af82c3d32981e121b5e7 GIT binary patch literal 6148 zcmeH~Jr2S!425mVP>H1@V-^m;4I%_5-~tF3K^+i#j?VMXLSaS~dY0@jc51bKLsN^0 z?w;4J$RHv;+$b9h6I0}!Tx68{^>MkK$MI$*w?)zl@IfZ~xlK?3DnJFO02QDDGg2TA z@_sd=XX2w!0V*&L1?>A!;KrJ4LH~3h_y_tMAK>5S|49o|DnJGPOaWc) zkNX{7D$mxB*R%R5tF~@%&@V@L`w2i|NAVi&hW%m-uqIm&6&Qa6Tm}Xz@KXg|*oF~o literal 0 HcmV?d00001 diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java new file mode 100644 index 00000000..f6cbf1ab --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java @@ -0,0 +1,4 @@ +package com.zipcodewilmington.scientific_calculator; + +public class CoreFunctionsTest { +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificFunctionsTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificFunctionsTest.java new file mode 100644 index 00000000..67b594d1 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificFunctionsTest.java @@ -0,0 +1,4 @@ +package com.zipcodewilmington.scientific_calculator; + +public class ScientificFunctionsTest { +} From eb68778ff9bcca57f2dc344e17c1f973b854f23d Mon Sep 17 00:00:00 2001 From: Giles Bradford Date: Fri, 7 Feb 2020 16:35:20 -0500 Subject: [PATCH 02/29] Test --- .../zipcodewilmington/scientificcalculator/CoreFunctions.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java index ed989149..0c434bbf 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java @@ -2,5 +2,7 @@ public class CoreFunctions { - public + public class Add{ + + } } From 098e0d789f2cb70d12915404d6977ca407976e5c Mon Sep 17 00:00:00 2001 From: Khalil Crumpler Date: Fri, 7 Feb 2020 16:41:16 -0500 Subject: [PATCH 03/29] added comment --- .../zipcodewilmington/scientificcalculator/MainApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 5f421325..cf4cc5f7 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -1,5 +1,5 @@ package com.zipcodewilmington.scientificcalculator; - +// /** * Created by leon on 2/9/18. */ From 7bdc7df41af0927854e3b2d2e39f42fa0aa1c713 Mon Sep 17 00:00:00 2001 From: Khalil Crumpler Date: Fri, 7 Feb 2020 16:48:12 -0500 Subject: [PATCH 04/29] add misc --- .../zipcodewilmington/scientificcalculator/MainApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index cf4cc5f7..8d5be953 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -1,5 +1,5 @@ package com.zipcodewilmington.scientificcalculator; -// +git br /** * Created by leon on 2/9/18. */ From ba4de8d2e72aea1384cab7ccb9536894711ec6a5 Mon Sep 17 00:00:00 2001 From: Khalil Crumpler Date: Fri, 7 Feb 2020 16:59:06 -0500 Subject: [PATCH 05/29] updated misc --- .../zipcodewilmington/scientificcalculator/MainApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 8d5be953..5f421325 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -1,5 +1,5 @@ package com.zipcodewilmington.scientificcalculator; -git br + /** * Created by leon on 2/9/18. */ From 82dfd07dbb2afbe7624cb26c22c1c9308de0e504 Mon Sep 17 00:00:00 2001 From: Giles Bradford Date: Fri, 7 Feb 2020 17:18:11 -0500 Subject: [PATCH 06/29] updating --- .../scientificcalculator/CoreFunctions.java | 12 ++++++++++++ .../scientificcalculator/MainApplication.java | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java index 0c434bbf..836b4b90 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java @@ -5,4 +5,16 @@ public class CoreFunctions { public class Add{ } + + public class Subtract{ + + } + + public class Multiply{ + + } + + public class Divide{ + + } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 5f421325..d8581a84 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -6,7 +6,7 @@ public class MainApplication { public static void main(String[] args) { Console.println("Welcome to my calculator!"); - String s = Console.getStringInput("Enter a string"); + String s = Console.getStringInput("What operation do you want to do?"); Integer i = Console.getIntegerInput("Enter an integer"); Double d = Console.getDoubleInput("Enter a double."); From ba9ee360278adc48ce08b07a8ce366e60813c017 Mon Sep 17 00:00:00 2001 From: Khalil Crumpler Date: Fri, 7 Feb 2020 17:57:40 -0500 Subject: [PATCH 07/29] added scientific functions --- .../scientificcalculator/ScientificFunctions.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java index 41356844..5929285e 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -1,4 +1,5 @@ package com.zipcodewilmington.scientificcalculator; public class ScientificFunctions { + public } From 4cf0b759b40bcf317001ce27160c098cbc48a888 Mon Sep 17 00:00:00 2001 From: Giles Bradford Date: Fri, 7 Feb 2020 18:07:08 -0500 Subject: [PATCH 08/29] Added empty constructor --- .gitignore | 1 + .../scientificcalculator/CoreFunctions.java | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index de469bb3..5557063f 100644 --- a/.gitignore +++ b/.gitignore @@ -149,6 +149,7 @@ fabric.properties .project .classpath .settings +.DS_Store #maven build target diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java index 836b4b90..67e2352c 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java @@ -2,8 +2,13 @@ public class CoreFunctions { + //This is a constructor for CLass + public void CoreFunctions() { + + } + public class Add{ - + } public class Subtract{ From 0ddeebc86f68d1395161e2be14c3db251f5ce87a Mon Sep 17 00:00:00 2001 From: Jeremy McCray Date: Fri, 7 Feb 2020 18:18:50 -0500 Subject: [PATCH 09/29] working on a test --- .gitignore | 2 +- pom.xml | 8 ++++++++ .../scientific_calculator/TestMainApplication.java | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index de469bb3..26d6478f 100644 --- a/.gitignore +++ b/.gitignore @@ -149,7 +149,7 @@ fabric.properties .project .classpath .settings - +.DS_Store #maven build target target/ \ No newline at end of file diff --git a/pom.xml b/pom.xml index e7cb4f6b..d8cd763e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,14 @@ com.zipcodewilmington scientific_calculator 1.0-SNAPSHOT + + + 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 94e8d987..34b296fb 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -1,7 +1,18 @@ package com.zipcodewilmington.scientific_calculator; +import com.zipcodewilmington.scientificcalculator.CoreFunctions; +import org.junit.Test; + /** * Created by leon on 2/9/18. */ public class TestMainApplication { + CoreFunctions mathTests = new CoreFunctions(); } +@Test +public class adderTest{ + + int assumed = 3; + int actual = mathTests.add(); + assertEquals( assumed, actual); +} \ No newline at end of file From 5173157081ced3aeca7a7f33454f80f83411cce6 Mon Sep 17 00:00:00 2001 From: Jeremy McCray Date: Fri, 7 Feb 2020 19:23:58 -0500 Subject: [PATCH 10/29] Added some adder tests --- .../scientificcalculator/CoreFunctions.java | 27 ++++++++++--------- .../CoreFunctionsTest.java | 27 +++++++++++++++++++ .../TestMainApplication.java | 16 ++++++----- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java index 836b4b90..9ec62e35 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java @@ -2,19 +2,20 @@ public class CoreFunctions { - public class Add{ - + public Integer Add (int a, int b){ + int sum = a+b; + return sum; } - public class Subtract{ - - } - - public class Multiply{ - - } - - public class Divide{ - - } +// public class Subtract{ +// +// } +// +// public class Multiply{ +// +// } +// +// public class Divide{ +// +// } } diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java index f6cbf1ab..b1df17ec 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java @@ -1,4 +1,31 @@ package com.zipcodewilmington.scientific_calculator; +import com.zipcodewilmington.scientificcalculator.CoreFunctions; +import org.junit.Assert; +import org.junit.Test; + public class CoreFunctionsTest { + CoreFunctions coreFunctions = new CoreFunctions(); + + @Test + public void positiveintegerAdderTest(){ + int assumed = 2; + int actual = coreFunctions.Add(1 ,1); + Assert.assertEquals( assumed, actual); + } + + @Test + public void NegativeIntegerAdderTest(){ + int assumed = -10; + int actual = coreFunctions.Add(0 ,-10); + Assert.assertEquals( assumed, actual); + } + + @Test + public void adderTest3(){ + int assumed = 3; + int actual = coreFunctions.Add(1 ,2); + Assert.assertEquals( assumed, actual); + } } + diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 34b296fb..66f54478 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -1,18 +1,20 @@ package com.zipcodewilmington.scientific_calculator; import com.zipcodewilmington.scientificcalculator.CoreFunctions; +import org.junit.Assert; import org.junit.Test; /** * Created by leon on 2/9/18. */ public class TestMainApplication { - CoreFunctions mathTests = new CoreFunctions(); + CoreFunctions coreFunctions = new CoreFunctions(); + + @Test + public void adderTest(){ + int assumed = 3; + int actual = coreFunctions.Add(1 ,2); + Assert.assertEquals( assumed, actual); + } } -@Test -public class adderTest{ - int assumed = 3; - int actual = mathTests.add(); - assertEquals( assumed, actual); -} \ No newline at end of file From 64a27972360127ecb19352aa6dcb446a83acc44a Mon Sep 17 00:00:00 2001 From: Khalil Crumpler Date: Fri, 7 Feb 2020 19:25:08 -0500 Subject: [PATCH 11/29] added scientific functions --- .../ScientificFunctions.class | Bin 0 -> 992 bytes .../ScientificFunctions.java | 53 +++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.class diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.class b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.class new file mode 100644 index 0000000000000000000000000000000000000000..cb589263d144d90f1d96a951f8a3faf31ac6d9c3 GIT binary patch literal 992 zcmZ{h!EVz)5Qb+PCvIIQr2*PPDKr#FQfLe`N7PHA9#8>^RNOb4#cbv5BF8BbFNHXP zIPd^G6yhHz6v@IqeCzo=pLTcr>-UeJMAWB#Kq2h~beHZi_8Be4eZ~Rf0plU#5u@!> z$EU8K+6!Y%b|R?K>An->4ctTv+Bh>-zn)LWIz5-;1c^68f~7O;4q+*`sQpaZSldj{ zy0Mo!o#|2DS6^0xWnW`ipZ{$SQaLfw4rHR>PIR1VJzG@1LU`t4LBYt)Q>9N0pI~RC z40bZ_jXIrMl^JJey$g9ML#k85r^ApQQ!}I|j3Y*m5iy=Jo-v*?j;Sf=M7e47*?d&E z@h6i^jg2#BquJFie2jS_GnYpH*;>#w-aJZhqv*}}LMsfR@h^HMvk#am#sp$qAZCRL z$~^L9o_R74*E07up9k9TK3t3gO5$Q_(K>!FKLH88E4YDb539ghJ^V)ED_(FUu$G4v zaFd!Kw;s?6Rk8Z*m)-BQ^5v>Izz4+ODq63X2$iA`La0NyQ6hLnVG{x$=4OddEecx@ zwjpel2(_ZH3*iog?GnK+3i}XR5Ozw0)uPab(1CEPL|7{dM-X}tZkGr_Q8x( Hg4_H7kW7|j literal 0 HcmV?d00001 diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java index 5929285e..ad63e8cd 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -1,5 +1,56 @@ package com.zipcodewilmington.scientificcalculator; public class ScientificFunctions { - public + + // returns sine + public double sine(double input){ + double number = input; + return Math.sin(number); + } + // returns cosine + public double cosine(double input){ + double number = input; + return Math.cos(number); + } + // returns tangent + public double tangent(double input){ + double number = input; + return Math.tan(number); + } + // inverse sine + public double inverseSine(double input){ + double number = input; + return Math.asin(number); + } + // inverse cosine + public double inverseCosine(double input){ + double number = input; + return Math.acos(number); + } + // inverse tangent + public double inverseTangent(double input){ + double number = input; + return Math.atan(number); + } + + // to radians + + public double radianCalc(double input){ + double number = input; + return Math.toRadians(number); + } + + // to degrees + public double degreesCalc(double input){ + double number = input; + return Math.toDegrees(number); + } + + // calc log + public double calcLog(double input){ + double number = input; + return Math.log(number); + } + + } From b82baadb5c02be9cc6f010882a20c63d0f2af66f Mon Sep 17 00:00:00 2001 From: Giles Bradford Date: Fri, 7 Feb 2020 19:39:16 -0500 Subject: [PATCH 12/29] Core Function updated. Compiling but still WIP --- .../scientificcalculator/Console.java | 5 ++- .../scientificcalculator/CoreFunctions.java | 38 ++++++++++++++++--- .../scientificcalculator/MainApplication.java | 21 +++++++--- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 83f0e97f..ce867507 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -27,6 +27,9 @@ public static Integer getIntegerInput(String prompt) { } 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/CoreFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java index 67e2352c..1b6e154a 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java @@ -1,25 +1,53 @@ package com.zipcodewilmington.scientificcalculator; +import java.lang.*; +import com.sun.tools.javac.util.StringUtils; + public class CoreFunctions { //This is a constructor for CLass - public void CoreFunctions() { + CoreFunctions() { + + } + + public boolean IsANumber(Double input) { + return true; + } + /*public class convertToDouble { + private String number1; + double convertedNumber = Double.parseDouble(number1); + }*/ + public Double Add(Double a, Double b) { + Double sum = a + b; + return sum; } - public class Add{ + public Double Subtract() { + return null; + } + public Double Multiply() { + return null; } - public class Subtract{ + public Double Divide() { + return null; + } + public Double SquareRoot() { + return null; } - public class Multiply{ + public Double Square() { + return null; + } + public Double Inverse() { + return null; } - public class Divide{ + public void Clear() { } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index d8581a84..e95fe370 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -5,13 +5,22 @@ */ public class MainApplication { public static void main(String[] args) { + //Without this object instance, no methods below would run. THIS IS CRUCIAL. + CoreFunctions coreFunctions = new CoreFunctions(); + Console.println("Welcome to my calculator!"); - String s = Console.getStringInput("What operation do you want to do?"); - Integer i = Console.getIntegerInput("Enter an integer"); - Double d = Console.getDoubleInput("Enter a double."); + Double number1 = Console.getDoubleInput("What number do you want to start with? : "); + coreFunctions.IsANumber(number1); + + String operator = Console.getStringInput("Please enter a second number : "); + + Double number2 = Console.getDoubleInput("Please enter a second number : "); + + + Console.println("The user input %s as the first number.", number1); + Console.println("The user input %s as the operator", operator); + Console.println("The user input %s as the second number.", number2); + - 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); } } From 1744e1a449b022ff1e3793743eefb3aef7c43074 Mon Sep 17 00:00:00 2001 From: Giles Bradford Date: Fri, 7 Feb 2020 21:41:00 -0500 Subject: [PATCH 13/29] adding code for the night --- .../scientificcalculator/CoreFunctions.java | 34 +++++++++++++------ .../scientificcalculator/MainApplication.java | 18 ++++++++-- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java index 1b6e154a..c32bbaf4 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java @@ -5,11 +5,18 @@ public class CoreFunctions { + Double display; + //This is a constructor for CLass - CoreFunctions() { + public CoreFunctions() { } + /*public double displayScreen() { + display = 0.0; + return display; + }*/ + public boolean IsANumber(Double input) { return true; } @@ -23,24 +30,29 @@ public Double Add(Double a, Double b) { return sum; } - public Double Subtract() { - return null; + public Double Subtract(Double a, Double b) { + Double sum = a - b; + return sum; } - public Double Multiply() { - return null; + public Double Multiply(Double a, Double b) { + Double sum = a * b; + return sum; } - public Double Divide() { - return null; + public Double Divide(Double a, Double b) { + Double sum = a / b; + return sum; } - public Double SquareRoot() { - return null; + public Double SquareRoot(Double a) { + Double sum = Math.sqrt(a); + return sum; } - public Double Square() { - return null; + public Double Square(Double a, Double b) { + Double sum = a - b; + return sum; } public Double Inverse() { diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index e95fe370..0d055f48 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -10,12 +10,24 @@ public static void main(String[] args) { Console.println("Welcome to my calculator!"); Double number1 = Console.getDoubleInput("What number do you want to start with? : "); - coreFunctions.IsANumber(number1); - - String operator = Console.getStringInput("Please enter a second number : "); + //coreFunctions.IsANumber(number1); + String operator = Console.getStringInput("Please enter your desired operator : "); Double number2 = Console.getDoubleInput("Please enter a second number : "); + if (operator.equals( "+")) { + System.out.println(coreFunctions.Add(number1, number2)); + } else if (operator == "-") { + System.out.println(coreFunctions.Subtract(number1, number2)); + } else if (operator == "*") { + System.out.println(coreFunctions.Multiply(number1, number2)); + } else if (operator == "/") { + System.out.println(coreFunctions.Divide(number1, number2)); + } else if (operator == "sqrt") { + System.out.println(coreFunctions.SquareRoot(number1)); + } else { + + } Console.println("The user input %s as the first number.", number1); Console.println("The user input %s as the operator", operator); From 979c8582ceb96dd0366492e07e41bd1d30ea59b0 Mon Sep 17 00:00:00 2001 From: Khalil Crumpler Date: Sat, 8 Feb 2020 11:01:52 -0500 Subject: [PATCH 14/29] added all fucntions under scientific --- .../scientificcalculator/CoreFunctions.java | 2 + .../ScientificFunctions.java | 48 ++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java index c32bbaf4..9c1f0db5 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java @@ -62,4 +62,6 @@ public Double Inverse() { public void Clear() { } + + } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java index ad63e8cd..29d861eb 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -2,6 +2,53 @@ public class ScientificFunctions { + public boolean IsANumber(Double input) { + return true; + } + + /*public class convertToDouble { + private String number1; + double convertedNumber = Double.parseDouble(number1); + }*/ + public Double Add(Double a, Double b) { + Double sum = a + b; + return sum; + } + + public Double Subtract(Double a, Double b) { + Double sum = a - b; + return sum; + } + + public Double Multiply(Double a, Double b) { + Double sum = a * b; + return sum; + } + + public Double Divide(Double a, Double b) { + Double sum = a / b; + return sum; + } + + public Double SquareRoot(Double a) { + Double sum = Math.sqrt(a); + return sum; + } + + public Double Square(Double a, Double b) { + Double sum = a - b; + return sum; + } + + public Double Inverse() { + return null; + } + + public void Clear() { + + } + + // returns sine public double sine(double input){ double number = input; @@ -52,5 +99,4 @@ public double calcLog(double input){ return Math.log(number); } - } From 51b1b7276b8308a4125348984050893bb79b4617 Mon Sep 17 00:00:00 2001 From: Jeremy McCray Date: Sat, 8 Feb 2020 11:56:06 -0500 Subject: [PATCH 15/29] added a a handful of working tests --- .../scientificcalculator/CoreFunctions.java | 2 +- .../CoreFunctionsTest.java | 83 +++++++++++++++++-- .../TestMainApplication.java | 4 +- 3 files changed, 79 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java index 0bebb893..56a7867e 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java @@ -6,7 +6,7 @@ public class CoreFunctions { //This is a constructor for CLass - CoreFunctions() { + public CoreFunctions() { } diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java index b1df17ec..c2459251 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java @@ -5,27 +5,94 @@ import org.junit.Test; public class CoreFunctionsTest { - CoreFunctions coreFunctions = new CoreFunctions(); + public CoreFunctions coreFunctions = new CoreFunctions(); @Test public void positiveintegerAdderTest(){ - int assumed = 2; - int actual = coreFunctions.Add(1 ,1); + Double assumed = 2.; + Double actual = coreFunctions.Add(1. ,1.); Assert.assertEquals( assumed, actual); } @Test public void NegativeIntegerAdderTest(){ - int assumed = -10; - int actual = coreFunctions.Add(0 ,-10); + Double assumed = -10.; + Double actual = coreFunctions.Add(0. ,-10.); Assert.assertEquals( assumed, actual); } @Test - public void adderTest3(){ - int assumed = 3; - int actual = coreFunctions.Add(1 ,2); + public void SubtractionTestPositiveReturn(){ + Double assumed = 1.; + Double actual = coreFunctions.Subtract(3. ,2.); + Assert.assertEquals( assumed, actual); + + } + + @Test + public void SubtractionTestZeroReturn(){ + Double assumed = 1.; + Double actual = coreFunctions.Subtract(3. ,3.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void SubtractionTestNegativeReturn(){ + Double assumed = -1.; + Double actual = coreFunctions.Subtract(3. ,4.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void MultiplicationPositiveReturn(){ + Double assumed = 9.; + Double actual = coreFunctions.Multiply(3. ,3.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void MultiplicationZeroReturn(){ + Double assumed = 0.; + Double actual = coreFunctions.Subtract(0. ,3.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void MultiplicationNegativeReturn(){ + Double assumed = -9.; + Double actual = coreFunctions.Subtract(-3. ,3.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void MultiplicationBothNegativeNumbers(){ + Double assumed = 9.; + Double actual = coreFunctions.Subtract(-3. ,-3.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void DivisionPositiveReturnWholeNumber(){ + Double assumed = 5.; + Double actual = coreFunctions.Subtract(10. ,2.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void DivisionPositiveReturnDecimal(){ + Double assumed = 5.; + Double actual = coreFunctions.Subtract(10. ,2.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void DivisionPositiveReturnDecimal(){ + Double assumed = 1.5; + Double actual = coreFunctions.Subtract(3 ,2.); Assert.assertEquals( assumed, actual); } + + + } diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 66f54478..64dfa486 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -9,12 +9,14 @@ */ public class TestMainApplication { CoreFunctions coreFunctions = new CoreFunctions(); - +/* @Test public void adderTest(){ int assumed = 3; int actual = coreFunctions.Add(1 ,2); Assert.assertEquals( assumed, actual); } + */ + } From 5011f42036475aea1aeb40d5d87cd7af770f5974 Mon Sep 17 00:00:00 2001 From: Khalil Crumpler Date: Sat, 8 Feb 2020 11:56:10 -0500 Subject: [PATCH 16/29] added/updated functions --- .../ScientificFunctions.java | 85 +++++++++++++------ 1 file changed, 59 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java index 29d861eb..a2962d56 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -26,8 +26,13 @@ public Double Multiply(Double a, Double b) { } public Double Divide(Double a, Double b) { - Double sum = a / b; - return sum; + if (b == 0){ + // tell user division by 0 is not allowed and to re enter input + } + else { + Double sum = a / b; + return sum; + } } public Double SquareRoot(Double a) { @@ -35,68 +40,96 @@ public Double SquareRoot(Double a) { return sum; } - public Double Square(Double a, Double b) { - Double sum = a - b; + public Double Square(Double a) { + Double sum = a*a; + return sum; + } + // Add all inverses? Multiplicative/additive/ + public Double Inverse(Double a) { + Double sum = (1/a); return sum; } + // reset memory to 0? + public void Clear() { - public Double Inverse() { - return null; } - public void Clear() { + public Double exponent(Double a, Double e){ + Double sum = Math.pow(a, e); + return sum; + } + public Double changeSign(Double a){ + if(a < 0){ + Double value = Math.abs(a); + } + else{ + value = value - (value*2); + } + return value; } + // returns sine - public double sine(double input){ - double number = input; + public Double sine(Double input){ + Double number = input; return Math.sin(number); } // returns cosine - public double cosine(double input){ - double number = input; + public Double cosine(Double input){ + Double number = input; return Math.cos(number); } // returns tangent - public double tangent(double input){ - double number = input; + public Double tangent(Double input){ + Double number = input; return Math.tan(number); } // inverse sine - public double inverseSine(double input){ - double number = input; + public Double inverseSine(Double input){ + Double number = input; return Math.asin(number); } // inverse cosine - public double inverseCosine(double input){ - double number = input; + public Double inverseCosine(Double input){ + Double number = input; return Math.acos(number); } // inverse tangent - public double inverseTangent(double input){ - double number = input; + public Double inverseTangent(Double input){ + Double number = input; return Math.atan(number); } // to radians - public double radianCalc(double input){ - double number = input; + public Double radian(Double input){ + Double number = input; return Math.toRadians(number); } // to degrees - public double degreesCalc(double input){ - double number = input; + public Double degree(Double input){ + Double number = input; return Math.toDegrees(number); } - // calc log - public double calcLog(double input){ - double number = input; + // calc natural log + public Double naturalLog(Double input){ + Double number = input; return Math.log(number); } + // calc base log + public Double baseLog(Double input){ + Double number = input; + return Math.log10(number); + } + + public Double inverseLog(Double input){ + Double number = Math.pow(10, input); + return number; + } + } From df46321ee00ee7b34afb33b28c3e3da27218c0cf Mon Sep 17 00:00:00 2001 From: Khalil Crumpler Date: Sat, 8 Feb 2020 12:15:08 -0500 Subject: [PATCH 17/29] added constructor --- .../ScientificFunctions.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java index a2962d56..1731c048 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -2,7 +2,11 @@ public class ScientificFunctions { - public boolean IsANumber(Double input) { + public ScientificFunctions(){ + + } + + public boolean isaNumber(Double input) { return true; } @@ -10,22 +14,22 @@ public boolean IsANumber(Double input) { private String number1; double convertedNumber = Double.parseDouble(number1); }*/ - public Double Add(Double a, Double b) { + public Double add(Double a, Double b) { Double sum = a + b; return sum; } - public Double Subtract(Double a, Double b) { + public Double subtract(Double a, Double b) { Double sum = a - b; return sum; } - public Double Multiply(Double a, Double b) { + public Double multiply(Double a, Double b) { Double sum = a * b; return sum; } - public Double Divide(Double a, Double b) { + public Double divide(Double a, Double b) { if (b == 0){ // tell user division by 0 is not allowed and to re enter input } @@ -35,17 +39,17 @@ public Double Divide(Double a, Double b) { } } - public Double SquareRoot(Double a) { + public Double squareRoot(Double a) { Double sum = Math.sqrt(a); return sum; } - public Double Square(Double a) { + public Double square(Double a) { Double sum = a*a; return sum; } // Add all inverses? Multiplicative/additive/ - public Double Inverse(Double a) { + public Double inverse(Double a) { Double sum = (1/a); return sum; } @@ -64,13 +68,11 @@ public Double changeSign(Double a){ Double value = Math.abs(a); } else{ - value = value - (value*2); + Double value = value - (value*2); } return value; } - - // returns sine public Double sine(Double input){ Double number = input; @@ -126,10 +128,16 @@ public Double baseLog(Double input){ Double number = input; return Math.log10(number); } - + // calc inverse log public Double inverseLog(Double input){ Double number = Math.pow(10, input); return number; } + // calc inverse natural log + public Double inverseNaturalLog(Double input){ + Double number = Math.pow(Math.E, input); + return number; + } + } From b2c4e87d217f31bdfcc885a2678fe22969922cf0 Mon Sep 17 00:00:00 2001 From: Khalil Crumpler Date: Sat, 8 Feb 2020 12:47:36 -0500 Subject: [PATCH 18/29] added factorial --- .../ScientificFunctions.class | Bin 992 -> 2625 bytes .../ScientificFunctions.java | 18 +++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.class b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.class index cb589263d144d90f1d96a951f8a3faf31ac6d9c3..3b2018cf2dbe02e6b3abefb6b49a2fd2d612e278 100644 GIT binary patch literal 2625 zcmaKsO>^615XV=3C63~}Hci?F2$W(sN!^sv7E)3}+(6nmY2!471lm5973WD5$&uv* z7`Q-ZV1|JUWy&zzIP}5+E|B2>cfJbWfEix?D=D^VBs}B4^sM%`&px{={r>kazY@`T zvQl)M@+o?iUSpX_(Ge=JTxFR}a&5{GDS;NVp&eott71|l(;NS=}apW&1A8R%~%y(q3(HU>I;qSvTiSnvH?qn ztP9Ve(2>mirq~rZLzvZE!D_%^D!YmhqEb=lQoz#y|HCGQo~SpNP!hhVn;YAxO?i8;Gqk*E}RVbht zyS!Rl=Xo!*SJR((9*Z3td&KY<{?VGXhf&HDyp<@|VZ*#YF*i^Q4V;B*iV4>i6Rxqt zv6kGyfE(@$?rbn(@KnU1lV=qg%*?f?anMwZtu&oh>T@(o$M99*-!LiMN9dDSjpC}{ z8bAFrDL>*yp{JlJim;Jll!WDJ*NxqeVZ~1(vG1XtZvs~)6nci9g|gom$QZ8OV?R-3 z9Di+}q6-s0G$C(;KI)==ASc7YY9M$N;1Iy)!ojUT@B~0U`>7^)-A{Fd(@a17h7ymc z?;vf<3!-r15w|jZ?zu)u#oogRbDT2tJf6lVqNWizLs=--APXXjYZnLGrx-#N#~-i2 zICatlfYVKkOUIa7I!5^*hrvl4% zhIyh{r3nP*hV~v*W}o6-ZCt)JGgqja@<7it^ID~Zd!Q_%>94<~99z*c}whGU%p*eb9!VCTXyH2}K{>>jWe!m+LZtO862c0L?S2VfG|Ca@R7vF-q@ z25bk|g>bAV0NVw&2kc@v)*FC*0PI6xm%_2W0PG`R9|L=-iH-YjNzVZFdvnNheE3cI zgwpgW$d`l2!T%#a2l)laDdJa%zXWT@f?u9dd;^Ax@#zuZ!{1Rq#&mdOgKhVt%A^RNOb4#cbv5BF8BbFNHXP zIPd^G6yhHz6v@IqeCzo=pLTcr>-UeJMAWB#Kq2h~beHZi_8Be4eZ~Rf0plU#5u@!> z$EU8K+6!Y%b|R?K>An->4ctTv+Bh>-zn)LWIz5-;1c^68f~7O;4q+*`sQpaZSldj{ zy0Mo!o#|2DS6^0xWnW`ipZ{$SQaLfw4rHR>PIR1VJzG@1LU`t4LBYt)Q>9N0pI~RC z40bZ_jXIrMl^JJey$g9ML#k85r^ApQQ!}I|j3Y*m5iy=Jo-v*?j;Sf=M7e47*?d&E z@h6i^jg2#BquJFie2jS_GnYpH*;>#w-aJZhqv*}}LMsfR@h^HMvk#am#sp$qAZCRL z$~^L9o_R74*E07up9k9TK3t3gO5$Q_(K>!FKLH88E4YDb539ghJ^V)ED_(FUu$G4v zaFd!Kw;s?6Rk8Z*m)-BQ^5v>Izz4+ODq63X2$iA`La0NyQ6hLnVG{x$=4OddEecx@ zwjpel2(_ZH3*iog?GnK+3i}XR5Ozw0)uPab(1CEPL|7{dM-X}tZkGr_Q8x( Hg4_H7kW7|j diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java index 1731c048..24f3f613 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -29,7 +29,7 @@ public Double multiply(Double a, Double b) { return sum; } - public Double divide(Double a, Double b) { + public Double divide(Double a, Double b){ if (b == 0){ // tell user division by 0 is not allowed and to re enter input } @@ -37,6 +37,7 @@ public Double divide(Double a, Double b) { Double sum = a / b; return sum; } + return null; } public Double squareRoot(Double a) { @@ -66,11 +67,12 @@ public Double exponent(Double a, Double e){ public Double changeSign(Double a){ if(a < 0){ Double value = Math.abs(a); + return value; } else{ - Double value = value - (value*2); + Double value = a - (a*2); + return value; } - return value; } // returns sine @@ -140,4 +142,14 @@ public Double inverseNaturalLog(Double input){ return number; } + // calculate factorial + public Integer factorial(Integer input){ + Integer number = 1; + for(int i = 2; i <= input; i++){ + number = number * i; + } + return number; + +} + } From a7fe8268a377982492c9b100a433f69772b0b203 Mon Sep 17 00:00:00 2001 From: Giles Bradford Date: Sat, 8 Feb 2020 12:48:10 -0500 Subject: [PATCH 19/29] Adding revisions to console and main file --- .../scientificcalculator/Calculator.java | 40 +++++++++++++++++++ .../scientificcalculator/Console.java | 33 ++++++++++++++- .../scientificcalculator/CoreFunctions.java | 3 -- .../scientificcalculator/MainApplication.java | 35 +++++++--------- 4 files changed, 85 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java new file mode 100644 index 00000000..41dfcb49 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java @@ -0,0 +1,40 @@ +package com.zipcodewilmington.scientificcalculator; + +public class Calculator { + Double currentValue = 0.0; + Double memory; + Double currentDisplay; + boolean appropriateInput; + Double answer; + + public Calculator() { + + } + + public Double getCurrentValue() { + return currentValue; + } + + /*public Double convertToDouble() { + String number1 = Double.parseDouble(); + return answer; + }*/ + + public boolean checkIfAppropriate(boolean isAppropriate) { + if (appropriateInput) { + return appropriateInput; + } else { + return appropriateInput = false; + } + } + + /*public getCurrentAnswer() { + + }*/ + + public Double updateCurrentValue() { + currentValue = answer; + return currentValue; + } + +} \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index ce867507..35ae29a9 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -26,10 +26,39 @@ public static Integer getIntegerInput(String prompt) { return null; } - public static Double getDoubleInput(String prompt) { + + + public static String getDoubleInput(String prompt) { Scanner scanner = new Scanner(System.in); println(prompt); - Double userInput = scanner.nextDouble(); + String userInput = scanner.nextLine(); return userInput; } + + public static String getFirstInput() { + return getDoubleInput("Please enter your first number: "); + } + + public static String getOperatorInput() { + return getDoubleInput("Please enter an operator"); + } + + public static String getSecondInput() { + return getDoubleInput("Please enter your first number: "); + } + + + + public String pickCalculator() { + return getDoubleInput("Please choose basic or scientific calculator: "); + + } + + int status = 0; + + /*while (status = 0) { + if (calculatorChoice.equals('basic')) { + + } + }*/ } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java index c32bbaf4..8352647b 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java @@ -59,7 +59,4 @@ public Double Inverse() { return null; } - public void Clear() { - - } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 0d055f48..57a583e0 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -1,38 +1,31 @@ package com.zipcodewilmington.scientificcalculator; -/** - * Created by leon on 2/9/18. - */ +import sun.util.calendar.CalendarUtils; + public class MainApplication { public static void main(String[] args) { //Without this object instance, no methods below would run. THIS IS CRUCIAL. CoreFunctions coreFunctions = new CoreFunctions(); + Calculator calc = new Calculator(); + + Console.println("Welcome to our calculator!"); + String calculatorChoice = Console.pickCalculator(); + String number1 = Console.getFirstInput(); + String operator = Console.getOperatorInput(); + String number2 = Console.getSecondInput(); + - Console.println("Welcome to my calculator!"); - Double number1 = Console.getDoubleInput("What number do you want to start with? : "); - //coreFunctions.IsANumber(number1); - String operator = Console.getStringInput("Please enter your desired operator : "); - Double number2 = Console.getDoubleInput("Please enter a second number : "); - if (operator.equals( "+")) { - System.out.println(coreFunctions.Add(number1, number2)); - } else if (operator == "-") { - System.out.println(coreFunctions.Subtract(number1, number2)); - } else if (operator == "*") { - System.out.println(coreFunctions.Multiply(number1, number2)); - } else if (operator == "/") { - System.out.println(coreFunctions.Divide(number1, number2)); - } else if (operator == "sqrt") { - System.out.println(coreFunctions.SquareRoot(number1)); - } else { - } + System.out.println(calc.getCurrentValue()); + + Console.println("The user input %s as the first number.", number1); Console.println("The user input %s as the operator", operator); Console.println("The user input %s as the second number.", number2); - + Console.println("Exiting Calculator"); } } From 0acf8f0e4d2f42daba7086af9b73e1c3891a6a42 Mon Sep 17 00:00:00 2001 From: Jeremy McCray Date: Sat, 8 Feb 2020 12:53:16 -0500 Subject: [PATCH 20/29] tests1252 --- .../CoreFunctionsTest.java | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java index c2459251..80ca1fbe 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java @@ -4,27 +4,26 @@ import org.junit.Assert; import org.junit.Test; -public class CoreFunctionsTest { - public CoreFunctions coreFunctions = new CoreFunctions(); +public class ScientificFunctions ScientificFunctions = new ScientificFunctions(); @Test public void positiveintegerAdderTest(){ Double assumed = 2.; - Double actual = coreFunctions.Add(1. ,1.); + Double actual = ScientificFunctions.add(1. ,1.); Assert.assertEquals( assumed, actual); } @Test public void NegativeIntegerAdderTest(){ Double assumed = -10.; - Double actual = coreFunctions.Add(0. ,-10.); + Double actual = ScientificFunctions.add(0. ,-10.); Assert.assertEquals( assumed, actual); } @Test public void SubtractionTestPositiveReturn(){ Double assumed = 1.; - Double actual = coreFunctions.Subtract(3. ,2.); + Double actual = ScientificFunctions.subtract(3. ,2.); Assert.assertEquals( assumed, actual); } @@ -32,67 +31,74 @@ public void SubtractionTestPositiveReturn(){ @Test public void SubtractionTestZeroReturn(){ Double assumed = 1.; - Double actual = coreFunctions.Subtract(3. ,3.); + Double actual = ScientificFunctions.subtract(3. ,3.); Assert.assertEquals( assumed, actual); } @Test public void SubtractionTestNegativeReturn(){ Double assumed = -1.; - Double actual = coreFunctions.Subtract(3. ,4.); + Double actual = ScientificFunctions.subtract(3. ,4.); Assert.assertEquals( assumed, actual); } @Test public void MultiplicationPositiveReturn(){ Double assumed = 9.; - Double actual = coreFunctions.Multiply(3. ,3.); + Double actual = ScientificFunctions.multiply(3. ,3.); Assert.assertEquals( assumed, actual); } @Test public void MultiplicationZeroReturn(){ Double assumed = 0.; - Double actual = coreFunctions.Subtract(0. ,3.); + Double actual = ScientificFunctions.multiply(0. ,3.); Assert.assertEquals( assumed, actual); } @Test public void MultiplicationNegativeReturn(){ Double assumed = -9.; - Double actual = coreFunctions.Subtract(-3. ,3.); + Double actual = ScientificFunctions.multiply(-3. ,3.); Assert.assertEquals( assumed, actual); } @Test public void MultiplicationBothNegativeNumbers(){ Double assumed = 9.; - Double actual = coreFunctions.Subtract(-3. ,-3.); + Double actual = ScientificFunctions.multiply(-3. ,-3.); Assert.assertEquals( assumed, actual); } @Test public void DivisionPositiveReturnWholeNumber(){ Double assumed = 5.; - Double actual = coreFunctions.Subtract(10. ,2.); + Double actual = ScientificFunctions.divide(10. ,2.); Assert.assertEquals( assumed, actual); } @Test public void DivisionPositiveReturnDecimal(){ Double assumed = 5.; - Double actual = coreFunctions.Subtract(10. ,2.); + Double actual = ScientificFunctions.divide(10. ,2.); Assert.assertEquals( assumed, actual); } @Test public void DivisionPositiveReturnDecimal(){ Double assumed = 1.5; - Double actual = coreFunctions.Subtract(3 ,2.); + Double actual = ScientificFunctions.divide(3 ,2.); Assert.assertEquals( assumed, actual); } +/* +@Test +public void degree(){ + Double assumed = 1.5; + Double actual = ScientificFunctions.divide(3 ,2.); + Assert.assertEquals( assumed, actual); + } - +*/ } From ee904399ef2164473b464c33200a60cd2dc46ccd Mon Sep 17 00:00:00 2001 From: Giles Bradford Date: Sat, 8 Feb 2020 13:49:25 -0500 Subject: [PATCH 21/29] updating my code to update Tests. --- .../scientificcalculator/Calculator.java | 6 ++-- .../scientificcalculator/Console.java | 35 +++++++++++++------ .../scientificcalculator/CoreFunctions.java | 1 + .../scientificcalculator/MainApplication.java | 20 +++++++---- .../CoreFunctionsTest.java | 3 +- 5 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java index 41dfcb49..f61c207f 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java @@ -1,14 +1,14 @@ package com.zipcodewilmington.scientificcalculator; public class Calculator { - Double currentValue = 0.0; + Double currentValue; Double memory; Double currentDisplay; boolean appropriateInput; Double answer; - public Calculator() { - + public Calculator(Double newCurrentValue) { + currentValue = newCurrentValue; } public Double getCurrentValue() { diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 35ae29a9..c2bf0c3d 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -35,30 +35,45 @@ public static String getDoubleInput(String prompt) { return userInput; } - public static String getFirstInput() { + public String getFirstInput() { return getDoubleInput("Please enter your first number: "); } - public static String getOperatorInput() { + public String getOperatorInput() { return getDoubleInput("Please enter an operator"); } - public static String getSecondInput() { + public String getSecondInput() { return getDoubleInput("Please enter your first number: "); } - public String pickCalculator() { + public String pickCalculator() { return getDoubleInput("Please choose basic or scientific calculator: "); } - int status = 0; - - /*while (status = 0) { - if (calculatorChoice.equals('basic')) { - + public void calcChoice(String calculatorChoice) { + System.out.println("1) Addition\n" + + "2) Subtraction\n" + + "3) Multiplication\n + " + + "4) Divide \n"); + if(calculatorChoice.equals("scientific")){ + System.out.println("5) Squarer\n" + + "6) degree\n" + + "7) natural log\n" + + "8) base log\n" + + "9) inverse log\n" + + "10) square root\n" + + "11) inverse\n" + + "12) square\n" + + "13) exponent\n" + + "14) change sign\n" + + "15) sine\n" + + "15) cos\n" + + "15) tan\n"); } - }*/ + + } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java index 4f2452b0..e091abd2 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFunctions.java @@ -59,3 +59,4 @@ public Double Inverse() { return null; } +} \ 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 57a583e0..c9635a2d 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -6,13 +6,21 @@ public class MainApplication { public static void main(String[] args) { //Without this object instance, no methods below would run. THIS IS CRUCIAL. CoreFunctions coreFunctions = new CoreFunctions(); - Calculator calc = new Calculator(); - + Calculator calc = new Calculator(0.0); + Console console = new Console(); Console.println("Welcome to our calculator!"); - String calculatorChoice = Console.pickCalculator(); - String number1 = Console.getFirstInput(); - String operator = Console.getOperatorInput(); - String number2 = Console.getSecondInput(); + String calculatorChoice = console.pickCalculator(); + + console.calcChoice(calculatorChoice); + + + + + String number1 = console.getFirstInput(); + String operator = console.getOperatorInput(); + String number2 = console.getSecondInput(); + + diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java index 80ca1fbe..bd9dd83b 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java @@ -4,7 +4,8 @@ import org.junit.Assert; import org.junit.Test; -public class ScientificFunctions ScientificFunctions = new ScientificFunctions(); +public class coreFunctionsTest { + ScientificFunctions ScientificFunctions = new ScientificFunctions(); @Test public void positiveintegerAdderTest(){ From dab68dd74cfa09323ea7ca10742a6096890dcaaa Mon Sep 17 00:00:00 2001 From: Jeremy McCray Date: Sat, 8 Feb 2020 13:50:11 -0500 Subject: [PATCH 22/29] added more tests 149 --- .../scientificcalculator/Console.java | 2 +- .../CoreFunctionsTest.java | 42 ++++++++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 35ae29a9..d6f8d30e 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -49,7 +49,7 @@ public static String getSecondInput() { - public String pickCalculator() { + public static String pickCalculator() { return getDoubleInput("Please choose basic or scientific calculator: "); } diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java index 80ca1fbe..40cf3a40 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java @@ -1,10 +1,12 @@ package com.zipcodewilmington.scientific_calculator; import com.zipcodewilmington.scientificcalculator.CoreFunctions; +import com.zipcodewilmington.scientificcalculator.ScientificFunctions; import org.junit.Assert; import org.junit.Test; -public class ScientificFunctions ScientificFunctions = new ScientificFunctions(); +public class CoreFunctionsTest { + ScientificFunctions ScientificFunctions = new ScientificFunctions(); @Test public void positiveintegerAdderTest(){ @@ -30,7 +32,7 @@ public void SubtractionTestPositiveReturn(){ @Test public void SubtractionTestZeroReturn(){ - Double assumed = 1.; + Double assumed = 0.; Double actual = ScientificFunctions.subtract(3. ,3.); Assert.assertEquals( assumed, actual); } @@ -79,26 +81,38 @@ public void DivisionPositiveReturnWholeNumber(){ @Test public void DivisionPositiveReturnDecimal(){ - Double assumed = 5.; - Double actual = ScientificFunctions.divide(10. ,2.); + Double assumed = 1.5; + Double actual = ScientificFunctions.divide(3. ,2.); + Assert.assertEquals( assumed, actual); + } + @Test + public void squareRootReturnPositiveWholeNumber(){ + Double assumed = 3.; + Double actual = ScientificFunctions.squareRoot(9. ); Assert.assertEquals( assumed, actual); } @Test - public void DivisionPositiveReturnDecimal(){ - Double assumed = 1.5; - Double actual = ScientificFunctions.divide(3 ,2.); + public void squareRootReturnPositiveDecimal(){ + Double assumed = 3.1622776601683795; + Double actual = ScientificFunctions.squareRoot(10. ); Assert.assertEquals( assumed, actual); } +/* + @Test + public void squareRootReturnZero(){ + String assumed = "Whatever logic my boys put"; + Double actual = ScientificFunctions.squareRoot(10. ); + Assert.assertEquals( assumed, actual); + }*/ /* -@Test -public void degree(){ - Double assumed = 1.5; - Double actual = ScientificFunctions.divide(3 ,2.); + @Test + public void squareRootReturnNegative(){ + String assumed = "Whatever logic my boys put"; + Double actual = ScientificFunctions.squareRoot(10. ); Assert.assertEquals( assumed, actual); - } + }*/ -*/ -} +} From d36cce5b6263b23a0183a815ad0be4b865f3bb74 Mon Sep 17 00:00:00 2001 From: Jeremy McCray Date: Sat, 8 Feb 2020 13:59:20 -0500 Subject: [PATCH 23/29] moved everything to the correct test class --- .../CoreFunctionsTest.java | 108 ----------------- .../ScientificFunctionsTest.java | 113 ++++++++++++++++++ 2 files changed, 113 insertions(+), 108 deletions(-) diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java index 40cf3a40..fe361311 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreFunctionsTest.java @@ -6,113 +6,5 @@ import org.junit.Test; public class CoreFunctionsTest { - ScientificFunctions ScientificFunctions = new ScientificFunctions(); - - @Test - public void positiveintegerAdderTest(){ - Double assumed = 2.; - Double actual = ScientificFunctions.add(1. ,1.); - Assert.assertEquals( assumed, actual); - } - - @Test - public void NegativeIntegerAdderTest(){ - Double assumed = -10.; - Double actual = ScientificFunctions.add(0. ,-10.); - Assert.assertEquals( assumed, actual); - } - - @Test - public void SubtractionTestPositiveReturn(){ - Double assumed = 1.; - Double actual = ScientificFunctions.subtract(3. ,2.); - Assert.assertEquals( assumed, actual); - - } - - @Test - public void SubtractionTestZeroReturn(){ - Double assumed = 0.; - Double actual = ScientificFunctions.subtract(3. ,3.); - Assert.assertEquals( assumed, actual); - } - - @Test - public void SubtractionTestNegativeReturn(){ - Double assumed = -1.; - Double actual = ScientificFunctions.subtract(3. ,4.); - Assert.assertEquals( assumed, actual); - } - - @Test - public void MultiplicationPositiveReturn(){ - Double assumed = 9.; - Double actual = ScientificFunctions.multiply(3. ,3.); - Assert.assertEquals( assumed, actual); - } - - @Test - public void MultiplicationZeroReturn(){ - Double assumed = 0.; - Double actual = ScientificFunctions.multiply(0. ,3.); - Assert.assertEquals( assumed, actual); - } - - @Test - public void MultiplicationNegativeReturn(){ - Double assumed = -9.; - Double actual = ScientificFunctions.multiply(-3. ,3.); - Assert.assertEquals( assumed, actual); - } - - @Test - public void MultiplicationBothNegativeNumbers(){ - Double assumed = 9.; - Double actual = ScientificFunctions.multiply(-3. ,-3.); - Assert.assertEquals( assumed, actual); - } - - @Test - public void DivisionPositiveReturnWholeNumber(){ - Double assumed = 5.; - Double actual = ScientificFunctions.divide(10. ,2.); - Assert.assertEquals( assumed, actual); - } - - @Test - public void DivisionPositiveReturnDecimal(){ - Double assumed = 1.5; - Double actual = ScientificFunctions.divide(3. ,2.); - Assert.assertEquals( assumed, actual); - } - @Test - public void squareRootReturnPositiveWholeNumber(){ - Double assumed = 3.; - Double actual = ScientificFunctions.squareRoot(9. ); - Assert.assertEquals( assumed, actual); - } - - @Test - public void squareRootReturnPositiveDecimal(){ - Double assumed = 3.1622776601683795; - Double actual = ScientificFunctions.squareRoot(10. ); - Assert.assertEquals( assumed, actual); - } -/* - @Test - public void squareRootReturnZero(){ - String assumed = "Whatever logic my boys put"; - Double actual = ScientificFunctions.squareRoot(10. ); - Assert.assertEquals( assumed, actual); - }*/ - -/* - @Test - public void squareRootReturnNegative(){ - String assumed = "Whatever logic my boys put"; - Double actual = ScientificFunctions.squareRoot(10. ); - Assert.assertEquals( assumed, actual); - }*/ - } diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificFunctionsTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificFunctionsTest.java index 67b594d1..a78a5ac2 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificFunctionsTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificFunctionsTest.java @@ -1,4 +1,117 @@ package com.zipcodewilmington.scientific_calculator; +import com.zipcodewilmington.scientificcalculator.ScientificFunctions; +import org.junit.Assert; +import org.junit.Test; + public class ScientificFunctionsTest { + com.zipcodewilmington.scientificcalculator.ScientificFunctions ScientificFunctions = new ScientificFunctions(); + + @Test + public void positiveintegerAdderTest(){ + Double assumed = 2.; + Double actual = ScientificFunctions.add(1. ,1.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void NegativeIntegerAdderTest(){ + Double assumed = -10.; + Double actual = ScientificFunctions.add(0. ,-10.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void SubtractionTestPositiveReturn(){ + Double assumed = 1.; + Double actual = ScientificFunctions.subtract(3. ,2.); + Assert.assertEquals( assumed, actual); + + } + + @Test + public void SubtractionTestZeroReturn(){ + Double assumed = 0.; + Double actual = ScientificFunctions.subtract(3. ,3.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void SubtractionTestNegativeReturn(){ + Double assumed = -1.; + Double actual = ScientificFunctions.subtract(3. ,4.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void MultiplicationPositiveReturn(){ + Double assumed = 9.; + Double actual = ScientificFunctions.multiply(3. ,3.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void MultiplicationZeroReturn(){ + Double assumed = 0.; + Double actual = ScientificFunctions.multiply(0. ,3.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void MultiplicationNegativeReturn(){ + Double assumed = -9.; + Double actual = ScientificFunctions.multiply(-3. ,3.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void MultiplicationBothNegativeNumbers(){ + Double assumed = 9.; + Double actual = ScientificFunctions.multiply(-3. ,-3.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void DivisionPositiveReturnWholeNumber(){ + Double assumed = 5.; + Double actual = ScientificFunctions.divide(10. ,2.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void DivisionPositiveReturnDecimal(){ + Double assumed = 1.5; + Double actual = ScientificFunctions.divide(3. ,2.); + Assert.assertEquals( assumed, actual); + } + @Test + public void squareRootReturnPositiveWholeNumber(){ + Double assumed = 3.; + Double actual = ScientificFunctions.squareRoot(9. ); + Assert.assertEquals( assumed, actual); + } + + @Test + public void squareRootReturnPositiveDecimal(){ + Double assumed = 3.1622776601683795; + Double actual = ScientificFunctions.squareRoot(10. ); + Assert.assertEquals( assumed, actual); + } +/* + @Test + public void squareRootReturnZero(){ + String assumed = "Whatever logic my boys put"; + Double actual = ScientificFunctions.squareRoot(10. ); + Assert.assertEquals( assumed, actual); + }*/ + +/* + @Test + public void squareRootReturnNegative(){ + String assumed = "Whatever logic my boys put"; + Double actual = ScientificFunctions.squareRoot(10. ); + Assert.assertEquals( assumed, actual); + }*/ + + } From 9e3c803f4d2ef9a64f9b5bc812b2313438aa58dc Mon Sep 17 00:00:00 2001 From: Jeremy McCray Date: Sat, 8 Feb 2020 15:19:27 -0500 Subject: [PATCH 24/29] added a bunch of tests and went to eat --- .../ScientificFunctionsTest.java | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificFunctionsTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificFunctionsTest.java index a78a5ac2..21da3e7a 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificFunctionsTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificFunctionsTest.java @@ -97,6 +97,68 @@ public void squareRootReturnPositiveDecimal(){ Double actual = ScientificFunctions.squareRoot(10. ); Assert.assertEquals( assumed, actual); } + + @Test + public void SquareReturnPositiveWholeNumber(){ + Double assumed = 4.; + Double actual = ScientificFunctions.square(2. ); + Assert.assertEquals( assumed, actual); + } + + @Test + public void SquareReturnNegativeWholeNumber(){ + Double assumed = -25.; + Double actual = ScientificFunctions.square(-5. ); + Assert.assertEquals( assumed, actual); + } + + @Test + public void SquareReturnPositiveDecimal(){ + Double assumed = 30.25; + Double actual = ScientificFunctions.square(5.5 ); + Assert.assertEquals( assumed, actual); + } + + @Test + public void SquareReturnNegativeDecimal(){ + Double assumed = -30.25; + Double actual = ScientificFunctions.square(-5.5 ); + Assert.assertEquals( assumed, actual); + } + + @Test + public void ChangeSignFromPositive(){ + Double assumed = -5.; + Double actual = ScientificFunctions.changeSign(5.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void ChangeSignFromNegative(){ + Double assumed = 5.; + Double actual = ScientificFunctions.changeSign(-5.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void SinePositiveNumber(){ + Double assumed = -0.5440211108893698; + Double actual = ScientificFunctions.sine(10.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void SineNegativeNumber(){ + Double assumed = 0.5440211108893698; + Double actual = ScientificFunctions.sine(-10.); + Assert.assertEquals( assumed, actual); + } + @Test + public void SineZeroNumber(){ + Double assumed = 0.; + Double actual = ScientificFunctions.sine(0.); + Assert.assertEquals( assumed, actual); + } /* @Test public void squareRootReturnZero(){ @@ -113,5 +175,82 @@ public void squareRootReturnNegative(){ Assert.assertEquals( assumed, actual); }*/ + @Test + public void CosineNegativeNumber(){ + Double assumed = -0.8390715290764524; + Double actual = ScientificFunctions.cosine(-10.); + Assert.assertEquals( assumed, actual); + } + @Test + public void CosinePositiveNumber(){ + Double assumed = -0.8390715290764524; + Double actual = ScientificFunctions.cosine(10.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void CosineZeroNumber(){ + Double assumed = 1.; + Double actual = ScientificFunctions.cosine(0.); + Assert.assertEquals( assumed, actual); + } + @Test + public void TangentZeroNumber(){ + Double assumed = 0.; + Double actual = ScientificFunctions.tangent(0.); + Assert.assertEquals( assumed, actual); + } + @Test + public void TangentPositiveNumber(){ + Double assumed = 0.6483608274590866; + Double actual = ScientificFunctions.tangent(10.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void TangentNegativeNumber(){ + Double assumed = -0.6483608274590866; + Double actual = ScientificFunctions.tangent(-10.); + Assert.assertEquals( assumed, actual); + } + @Test + public void ExponentPositiveNumbers(){ + Double assumed = 4.; + Double actual = ScientificFunctions.exponent(2.,2.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void ExponentNegativeNumbers(){ + Double assumed = 4.; + Double actual = ScientificFunctions.exponent(-2.,2.); + Assert.assertEquals( assumed, actual); + } + @Test + public void ExponentNegativeExponentPositiveNumber(){ + Double assumed = .25; + Double actual = ScientificFunctions.exponent(2.,-2.); + Assert.assertEquals( assumed, actual); + } + @Test + public void ExponentNegativeExponentNegativeNumber(){ + Double assumed = .25; + Double actual = ScientificFunctions.exponent(-2.,-2.); + Assert.assertEquals( assumed, actual); + } + + @Test + public void ExponentZeroPositiveNumber(){ + Double assumed = 1.; + Double actual = ScientificFunctions.exponent(2.,.0); + Assert.assertEquals( assumed, actual); + } + + @Test + public void ExponentZeroZeroNumber(){ + Double assumed = 1.; + Double actual = ScientificFunctions.exponent(0.,.0); + Assert.assertEquals( assumed, actual); + } } From 37b930afb8d34c46172f46b799ccd807dd2c7bd2 Mon Sep 17 00:00:00 2001 From: Giles Bradford Date: Sat, 8 Feb 2020 21:45:14 -0500 Subject: [PATCH 25/29] Adding a working calculator that literally only does math. --- .../scientificcalculator/Calculator.java | 82 +++++++- .../scientificcalculator/Console.java | 57 +----- .../scientificcalculator/MainApplication.java | 185 +++++++++++++++--- .../ScientificFunctions.java | 55 ++++-- .../scientificcalculator/User.java | 21 ++ 5 files changed, 292 insertions(+), 108 deletions(-) create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/User.java diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java index f61c207f..2441b834 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java @@ -1,5 +1,73 @@ package com.zipcodewilmington.scientificcalculator; +import java.util.Scanner; +public class Calculator { + + public Double operator; + public Double firstOption; + public Double secondOption; + + public Calculator() { + + } + + public Double getInputFromUser() { + Scanner scanner = new Scanner(System.in); + Double userInput = scanner.nextDouble(); + return userInput; + } + + public void setFirstInput(Double input){ + firstOption = input; + } + + public void setSecondOptionInput(Double input){ + secondOption = input; + } + + public void setOperator(Double input){ + operator = input; + } + + public Double chooseCalc() { + return null; + } + + public Double getFirstNumber() { + return firstOption; + } + + public Double getSecondNumber() { + return secondOption; + } + +} + + + + + + + + + + + + + + + + + + + + + + + + + +/* public class Calculator { Double currentValue; Double memory; @@ -15,10 +83,12 @@ public Double getCurrentValue() { return currentValue; } - /*public Double convertToDouble() { + */ +/*public Double convertToDouble() { String number1 = Double.parseDouble(); return answer; - }*/ + }*//* + public boolean checkIfAppropriate(boolean isAppropriate) { if (appropriateInput) { @@ -28,13 +98,15 @@ public boolean checkIfAppropriate(boolean isAppropriate) { } } - /*public getCurrentAnswer() { + */ +/*public getCurrentAnswer() { + + }*//* - }*/ public Double updateCurrentValue() { currentValue = answer; return currentValue; } -} \ No newline at end of file +}*/ diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 27b569f8..f450428f 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -22,58 +22,11 @@ public static String getStringInput(String prompt) { return userInput; } - public static Integer getIntegerInput(String prompt) { + /*public static Integer getIntegerInput(String prompt) { return null; } - - - public static String getDoubleInput(String prompt) { - Scanner scanner = new Scanner(System.in); - println(prompt); - String userInput = scanner.nextLine(); - return userInput; - } - - public String getFirstInput() { - return getDoubleInput("Please enter your first number: "); - } - - public String getOperatorInput() { - return getDoubleInput("Please enter an operator"); - } - - public String getSecondInput() { - return getDoubleInput("Please enter your first number: "); - } - - - public String pickCalculator() { - return getDoubleInput("Please choose basic or scientific calculator: "); - - } - - public void calcChoice(String calculatorChoice) { - System.out.println("Please choose an option from the below Menu;\n" + - "1) Addition\n" + - "2) Subtraction\n" + - "3) Multiplication\n" + - "4) Divide \n"); - if(calculatorChoice.equals("scientific")){ - System.out.println("5) Square\n" + - "6) degree\n" + - "7) natural log\n" + - "8) base log\n" + - "9) inverse log\n" + - "10) square root\n" + - "11) inverse\n" + - "12) square\n" + - "13) exponent\n" + - "14) change sign\n" + - "15) sine\n" + - "15) cos\n" + - "15) tan\n"); - } - - } -} + public static Double getDoubleInput(String prompt) { + return null; + }*/ +} \ 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 c9635a2d..1da4a925 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -1,39 +1,164 @@ package com.zipcodewilmington.scientificcalculator; +import java.util.Scanner; import sun.util.calendar.CalendarUtils; public class MainApplication { public static void main(String[] args) { - //Without this object instance, no methods below would run. THIS IS CRUCIAL. - CoreFunctions coreFunctions = new CoreFunctions(); - Calculator calc = new Calculator(0.0); - Console console = new Console(); - Console.println("Welcome to our calculator!"); - String calculatorChoice = console.pickCalculator(); - - console.calcChoice(calculatorChoice); - - - - - String number1 = console.getFirstInput(); - String operator = console.getOperatorInput(); - String number2 = console.getSecondInput(); - - - - - - - - System.out.println(calc.getCurrentValue()); - - - - Console.println("The user input %s as the first number.", number1); - Console.println("The user input %s as the operator", operator); - Console.println("The user input %s as the second number.", number2); - Console.println("Exiting Calculator"); + /*//This allows us to use all methods from the 'Calculator.java' class. + + System.out.println("Please choose 'basic' or 'scientific' calculator: "); + //the method below calls the 'getInputFromUser' method on the 'calc' object created on line 9. + Double input = calc.getInputFromUser(); + //the below line calls the 'checkBasicsOrScience' method and stores the user input as 'newInput' + //because of the parameter that exists in the method. + calc.checkBasicOrScience(input);*/ + + Calculator calc = new Calculator(); + User user = new User(0.); + ScientificFunctions func = new ScientificFunctions(); + int y = 2; + do { + try { + System.out.println("Please choose either '1' for 'Basic' or '2' for 'Scientific' calculator"); + Double choice = calc.getInputFromUser(); + + if (choice.equals(1.)) { + System.out.println("Please choose an option from the below Menu;\n" + + "1) Addition\n" + + "2) Subtraction\n" + + "3) Multiplication\n" + + "4) Divide \n"); + + + y = 1; + } else if (choice.equals(2.)){ + System.out.println("Please choose an option from the below Menu;\n" + + "1) Addition\n" + + "2) Subtraction\n" + + "3) Multiplication\n" + + "4) Divide \n" + + "5) degree\n" + + "6) natural log\n" + + "7) base log\n" + + "8) inverse log\n" + + "9) square root\n" + + "10) inverse\n" + + "11) square\n" + + "12) exponent\n" + + "13) change sign\n" + + "14) sine\n" + + "15) cos\n" + + "16) tan\n"+ + "17) inverseCosine\n"+ + "18) inverseTangent\n"+ + "19) radian\n"+ + "20) factorial\n"+ + "21) fibonacci\n"); + + y = 1; + } else { + System.out.println("Invalid input"); + } + } catch (Exception e) { + System.out.println("Sorry bad input"); + } + } while (y == 2); + + + Double operator = calc.getInputFromUser(); + + + + int x = 2; + do { + try { + System.out.println("Enter your first number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + System.out.println("Enter your Second Number"); + Double secondNum = calc.getInputFromUser(); + calc.setSecondOptionInput(secondNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + + + + + + + if (operator.equals(1.)) { + Double ans = ScientificFunctions.add(calc.getFirstNumber(), calc.getSecondNumber()); + System.out.println(ans); + } else if (operator.equals(2.)) { + Double ans = ScientificFunctions.subtract(calc.getFirstNumber(), calc.getSecondNumber()); + System.out.println(ans); + } else if (operator.equals(3.)) { + Double ans = ScientificFunctions.multiply(calc.getFirstNumber(), calc.getSecondNumber()); + System.out.println(ans); + } else if (operator.equals(4.)) { + Double ans = ScientificFunctions.divide(calc.getFirstNumber(), calc.getSecondNumber()); + System.out.println(ans); + } else if (operator.equals(5.)) { + Double ans = ScientificFunctions.degree(calc.getFirstNumber()); + System.out.println(ans); + } else if (operator.equals(6.)) { + Double ans = ScientificFunctions.naturalLog(calc.getFirstNumber()); + System.out.println(ans); + } else if (operator.equals(7.)) { + Double ans = ScientificFunctions.baseLog(calc.getFirstNumber()); + System.out.println(ans); + } else if (operator.equals(8.)) { + Double ans = ScientificFunctions.inverseLog(calc.getFirstNumber()); + System.out.println(ans); + } else if (operator.equals(9.)) { + Double ans = ScientificFunctions.squareRoot(calc.getFirstNumber()); + System.out.println(ans); + } else if (operator.equals(10.)) { + Double ans = ScientificFunctions.inverse(calc.getFirstNumber()); + System.out.println(ans); + } else if (operator.equals(11.)) { + Double ans = ScientificFunctions.square(calc.getFirstNumber()); + System.out.println(ans); + } else if (operator.equals(12.)) { + Double ans = ScientificFunctions.exponent(calc.getFirstNumber(), calc.getSecondNumber()); + System.out.println(ans); + } else if (operator.equals(13.)) { + Double ans = ScientificFunctions.changeSign(calc.getFirstNumber()); + System.out.println(ans); + } else if (operator.equals(14.)) { + Double ans = ScientificFunctions.sine(calc.getFirstNumber()); + System.out.println(ans); + } else if (operator.equals(15.)) { + Double ans = ScientificFunctions.cosine(calc.getFirstNumber()); + System.out.println(ans); + } else if (operator.equals(16.)) { + Double ans = ScientificFunctions.tangent(calc.getFirstNumber()); + System.out.println(ans); + } else if (operator.equals(17.)) { + Double ans = ScientificFunctions.inverseCosine(calc.getFirstNumber()); + System.out.println(ans); + } else if (operator.equals(18.)) { + Double ans = ScientificFunctions.inverseTangent(calc.getFirstNumber()); + System.out.println(ans); + } else if (operator.equals(19.)) { + Double ans = ScientificFunctions.radian(calc.getFirstNumber()); + } else if (operator.equals(20.)) { + Double ans = ScientificFunctions.factorial(calc.getFirstNumber()); + System.out.println(ans); + } else if (operator.equals(21.)) { + String ans = ScientificFunctions.fibonacci(calc.getFirstNumber()); + System.out.println(ans); + } else { + System.out.println("uhoh"); + } + + + System.out.println("Your answer is"); } } + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java index 24f3f613..a2733a38 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -14,22 +14,22 @@ public boolean isaNumber(Double input) { private String number1; double convertedNumber = Double.parseDouble(number1); }*/ - public Double add(Double a, Double b) { + public static Double add(Double a, Double b) { Double sum = a + b; return sum; } - public Double subtract(Double a, Double b) { + public static Double subtract(Double a, Double b) { Double sum = a - b; return sum; } - public Double multiply(Double a, Double b) { + public static Double multiply(Double a, Double b) { Double sum = a * b; return sum; } - public Double divide(Double a, Double b){ + public static Double divide(Double a, Double b){ if (b == 0){ // tell user division by 0 is not allowed and to re enter input } @@ -40,17 +40,17 @@ public Double divide(Double a, Double b){ return null; } - public Double squareRoot(Double a) { + public static Double squareRoot(Double a) { Double sum = Math.sqrt(a); return sum; } - public Double square(Double a) { + public static Double square(Double a) { Double sum = a*a; return sum; } // Add all inverses? Multiplicative/additive/ - public Double inverse(Double a) { + public static Double inverse(Double a) { Double sum = (1/a); return sum; } @@ -59,12 +59,12 @@ public void Clear() { } - public Double exponent(Double a, Double e){ + public static Double exponent(Double a, Double e){ Double sum = Math.pow(a, e); return sum; } - public Double changeSign(Double a){ + public static Double changeSign(Double a){ if(a < 0){ Double value = Math.abs(a); return value; @@ -76,17 +76,17 @@ public Double changeSign(Double a){ } // returns sine - public Double sine(Double input){ + public static Double sine(Double input){ Double number = input; return Math.sin(number); } // returns cosine - public Double cosine(Double input){ + public static Double cosine(Double input){ Double number = input; return Math.cos(number); } // returns tangent - public Double tangent(Double input){ + public static Double tangent(Double input){ Double number = input; return Math.tan(number); } @@ -96,42 +96,42 @@ public Double inverseSine(Double input){ return Math.asin(number); } // inverse cosine - public Double inverseCosine(Double input){ + public static Double inverseCosine(Double input){ Double number = input; return Math.acos(number); } // inverse tangent - public Double inverseTangent(Double input){ + public static Double inverseTangent(Double input){ Double number = input; return Math.atan(number); } // to radians - public Double radian(Double input){ + public static Double radian(Double input){ Double number = input; return Math.toRadians(number); } // to degrees - public Double degree(Double input){ + public static Double degree(Double input){ Double number = input; return Math.toDegrees(number); } // calc natural log - public Double naturalLog(Double input){ + public static Double naturalLog(Double input){ Double number = input; return Math.log(number); } // calc base log - public Double baseLog(Double input){ + public static Double baseLog(Double input){ Double number = input; return Math.log10(number); } // calc inverse log - public Double inverseLog(Double input){ + public static Double inverseLog(Double input){ Double number = Math.pow(10, input); return number; } @@ -143,13 +143,26 @@ public Double inverseNaturalLog(Double input){ } // calculate factorial - public Integer factorial(Integer input){ - Integer number = 1; + public static Double factorial(Double input){ + Double number = 1.; for(int i = 2; i <= input; i++){ number = number * i; } return number; } + public static String fibonacci(Double input){ + Double maxNumber = input; + Integer previousNumber = 0; + Integer nextNumber = 1; + String str = ""; + for (int i = 1; i <= maxNumber; i++){ + str += " " + previousNumber; + int sum = previousNumber + nextNumber; + previousNumber = nextNumber; + nextNumber = sum; + } + return str; + } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/User.java b/src/main/java/com/zipcodewilmington/scientificcalculator/User.java new file mode 100644 index 00000000..9a37306e --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/User.java @@ -0,0 +1,21 @@ +package com.zipcodewilmington.scientificcalculator; + +import java.util.Scanner; + +public class User { + + Double usersOperator; + + public User (Double usersOperator) { + this.usersOperator = usersOperator; + } + + public Double getInputFromUser() { + Scanner scanner = new Scanner(System.in); + Double userInput = scanner.nextDouble(); + return userInput; + } + + +} + From 999474d7119c2ae9a7fcff639cb2507c4655adc6 Mon Sep 17 00:00:00 2001 From: Giles Bradford Date: Sun, 9 Feb 2020 16:45:22 -0500 Subject: [PATCH 26/29] Commiting what works --- .../scientificcalculator/Calculator.java | 13 +- .../scientificcalculator/MainApplication.java | 551 +++++++++++++----- .../ScientificFunctions.java | 9 + .../scientificcalculator/User.java | 2 - 4 files changed, 428 insertions(+), 147 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java index 2441b834..37048813 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java @@ -6,11 +6,22 @@ public class Calculator { public Double operator; public Double firstOption; public Double secondOption; + public Double ans; + public String stringAns; public Calculator() { } + public Double setAns(Double ans) { + this.ans = ans; + return ans; + } + + public Double getAns() { + return this.ans; + } + public Double getInputFromUser() { Scanner scanner = new Scanner(System.in); Double userInput = scanner.nextDouble(); @@ -62,8 +73,6 @@ public Double getSecondNumber() { - - diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 1da4a925..8085caba 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -13,152 +13,417 @@ public static void main(String[] args) { //the below line calls the 'checkBasicsOrScience' method and stores the user input as 'newInput' //because of the parameter that exists in the method. calc.checkBasicOrScience(input);*/ + boolean t = true; + while (t) { - Calculator calc = new Calculator(); - User user = new User(0.); - ScientificFunctions func = new ScientificFunctions(); - int y = 2; - do { - try { - System.out.println("Please choose either '1' for 'Basic' or '2' for 'Scientific' calculator"); - Double choice = calc.getInputFromUser(); - - if (choice.equals(1.)) { - System.out.println("Please choose an option from the below Menu;\n" + - "1) Addition\n" + - "2) Subtraction\n" + - "3) Multiplication\n" + - "4) Divide \n"); - - - y = 1; - } else if (choice.equals(2.)){ - System.out.println("Please choose an option from the below Menu;\n" + - "1) Addition\n" + - "2) Subtraction\n" + - "3) Multiplication\n" + - "4) Divide \n" + - "5) degree\n" + - "6) natural log\n" + - "7) base log\n" + - "8) inverse log\n" + - "9) square root\n" + - "10) inverse\n" + - "11) square\n" + - "12) exponent\n" + - "13) change sign\n" + - "14) sine\n" + - "15) cos\n" + - "16) tan\n"+ - "17) inverseCosine\n"+ - "18) inverseTangent\n"+ - "19) radian\n"+ - "20) factorial\n"+ - "21) fibonacci\n"); - - y = 1; - } else { - System.out.println("Invalid input"); + Calculator calc = new Calculator(); + User user = new User(0.); + ScientificFunctions func = new ScientificFunctions(); + + + int y = 2; + do { + try { + System.out.println("Please choose either '1' for 'Basic' or '2' for 'Scientific' calculator"); + Double choice = calc.getInputFromUser(); + + if (choice.equals(1.)) { + System.out.println("Please choose an option from the below Menu by selecting " + + "it's corresponding number;\n" + + "1) Addition\n" + + "2) Subtraction\n" + + "3) Multiplication\n" + + "4) Divide \n"); + + + y = 1; + } else if (choice.equals(2.)) { + System.out.println("Please choose an option from the below Menu;\n" + + "1) Addition\n" + + "2) Subtraction\n" + + "3) Multiplication\n" + + "4) Divide \n" + + "5) degree\n" + + "6) natural log\n" + + "7) base log\n" + + "8) inverse log\n" + + "9) square root\n" + + "10) inverse\n" + + "11) square\n" + + "12) exponent\n" + + "13) change sign\n" + + "14) sine\n" + + "15) cos\n" + + "16) tan\n" + + "17) inverseCosine\n" + + "18) inverseTangent\n" + + "19) radian\n" + + "20) factorial\n" + + "21) fibonacci\n"); + + y = 1; + } else { + System.out.println("Invalid input"); + } + } catch (Exception e) { + System.out.println("Sorry bad input"); } - } catch (Exception e) { - System.out.println("Sorry bad input"); - } - } while (y == 2); - - - Double operator = calc.getInputFromUser(); - - - - int x = 2; - do { - try { - System.out.println("Enter your first number"); - Double firstNum = calc.getInputFromUser(); - calc.setFirstInput(firstNum); - System.out.println("Enter your Second Number"); - Double secondNum = calc.getInputFromUser(); - calc.setSecondOptionInput(secondNum); - x = 1; - } catch (Exception e) { - System.out.println("Sorry, bad input"); - } - } while (x == 2); - - - - - - - if (operator.equals(1.)) { - Double ans = ScientificFunctions.add(calc.getFirstNumber(), calc.getSecondNumber()); - System.out.println(ans); - } else if (operator.equals(2.)) { - Double ans = ScientificFunctions.subtract(calc.getFirstNumber(), calc.getSecondNumber()); - System.out.println(ans); - } else if (operator.equals(3.)) { - Double ans = ScientificFunctions.multiply(calc.getFirstNumber(), calc.getSecondNumber()); - System.out.println(ans); - } else if (operator.equals(4.)) { - Double ans = ScientificFunctions.divide(calc.getFirstNumber(), calc.getSecondNumber()); - System.out.println(ans); - } else if (operator.equals(5.)) { - Double ans = ScientificFunctions.degree(calc.getFirstNumber()); - System.out.println(ans); - } else if (operator.equals(6.)) { - Double ans = ScientificFunctions.naturalLog(calc.getFirstNumber()); - System.out.println(ans); - } else if (operator.equals(7.)) { - Double ans = ScientificFunctions.baseLog(calc.getFirstNumber()); - System.out.println(ans); - } else if (operator.equals(8.)) { - Double ans = ScientificFunctions.inverseLog(calc.getFirstNumber()); - System.out.println(ans); - } else if (operator.equals(9.)) { - Double ans = ScientificFunctions.squareRoot(calc.getFirstNumber()); - System.out.println(ans); - } else if (operator.equals(10.)) { - Double ans = ScientificFunctions.inverse(calc.getFirstNumber()); - System.out.println(ans); - } else if (operator.equals(11.)) { - Double ans = ScientificFunctions.square(calc.getFirstNumber()); - System.out.println(ans); - } else if (operator.equals(12.)) { - Double ans = ScientificFunctions.exponent(calc.getFirstNumber(), calc.getSecondNumber()); - System.out.println(ans); - } else if (operator.equals(13.)) { - Double ans = ScientificFunctions.changeSign(calc.getFirstNumber()); - System.out.println(ans); - } else if (operator.equals(14.)) { - Double ans = ScientificFunctions.sine(calc.getFirstNumber()); - System.out.println(ans); - } else if (operator.equals(15.)) { - Double ans = ScientificFunctions.cosine(calc.getFirstNumber()); - System.out.println(ans); - } else if (operator.equals(16.)) { - Double ans = ScientificFunctions.tangent(calc.getFirstNumber()); - System.out.println(ans); - } else if (operator.equals(17.)) { - Double ans = ScientificFunctions.inverseCosine(calc.getFirstNumber()); - System.out.println(ans); - } else if (operator.equals(18.)) { - Double ans = ScientificFunctions.inverseTangent(calc.getFirstNumber()); - System.out.println(ans); - } else if (operator.equals(19.)) { - Double ans = ScientificFunctions.radian(calc.getFirstNumber()); - } else if (operator.equals(20.)) { - Double ans = ScientificFunctions.factorial(calc.getFirstNumber()); - System.out.println(ans); - } else if (operator.equals(21.)) { - String ans = ScientificFunctions.fibonacci(calc.getFirstNumber()); - System.out.println(ans); - } else { - System.out.println("uhoh"); - } + } while (y == 2); +//This is to error handle 1-4 =============== +/* int test = 2; + do { + try { + Double operator = calc.getInputFromUser(); + test = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (test == 2);*/ - System.out.println("Your answer is"); +// end process =================================== + int test = 2; + do { + try { + Double operator = calc.getInputFromUser(); - } -} + if (operator.equals(1.)) { + int x = 2; + do { + try { + System.out.println("Enter your first number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + System.out.println("Enter your Second Number"); + Double secondNum = calc.getInputFromUser(); + calc.setSecondOptionInput(secondNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.add(calc.getFirstNumber(), calc.getSecondNumber()); + calc.setAns(ans); + } else if (operator.equals(2.)) { + int x = 2; + do { + try { + System.out.println("Enter your first number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + System.out.println("Enter your Second Number"); + Double secondNum = calc.getInputFromUser(); + calc.setSecondOptionInput(secondNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.subtract(calc.getFirstNumber(), calc.getSecondNumber()); + calc.setAns(ans); + } else if (operator.equals(3.)) { + int x = 2; + do { + try { + System.out.println("Enter your first number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + System.out.println("Enter your Second Number"); + Double secondNum = calc.getInputFromUser(); + calc.setSecondOptionInput(secondNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.multiply(calc.getFirstNumber(), calc.getSecondNumber()); + calc.setAns(ans); + } else if (operator.equals(4.)) { + int x = 2; + do { + try { + System.out.println("Enter your first number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + System.out.println("Enter your Second Number"); + Double secondNum = calc.getInputFromUser(); + if (secondNum.equals(0.)) { + System.out.println("Err"); + } else { + calc.setSecondOptionInput(secondNum); + x = 1; + } + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.divide(calc.getFirstNumber(), calc.getSecondNumber()); + calc.setAns(ans); +//--------------------------Basic--------------------------------------------- + + } + if (operator.equals(5.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.degree(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(6.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.naturalLog(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(7.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.baseLog(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(8.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.inverseLog(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(9.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.squareRoot(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(10.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.inverse(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(11.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.square(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(12.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.exponent(calc.getFirstNumber(), calc.getSecondNumber()); + calc.setAns(ans); + } else if (operator.equals(13.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.changeSign(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(14.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.sine(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(15.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.cosine(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(16.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.tangent(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(17.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.inverseCosine(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(18.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.inverseTangent(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(19.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.radian(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(20.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.factorial(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(21.)) { + String ans = ScientificFunctions.fibonacci(calc.getFirstNumber()); + } else { + //System.out.println("Error"); + } + test++; + } catch (Exception e) { + System.out.println("Sorry, bad input. Please enter a valid choice(number): "); + } + } while (test == 2); + System.out.println("Your answer is " + calc.getAns() + ""); + + + System.out.println("If you wish to convert your number to hexadecimal(1), Octal(2), or Binary(3), " + + "please enter the corresponding number. You may also press 0 to reset the calculator."); + int q = 2; + do { + try { + Double temp = calc.getInputFromUser(); + if (temp.equals(1.)) { + System.out.println("Your Hexadecimal answer for " + calc.getAns() + " is " + + ScientificFunctions.Hexadecimal(calc.getAns().intValue())); + } + else if (temp.equals(2.)) { + System.out.println("Your Octal answer for " + calc.getAns() + " is " + + ScientificFunctions.Octal(calc.getAns().intValue())); + } + else if (temp.equals(3.)) { + System.out.println("Your Binary answer for " + calc.getAns() + " is " + + ScientificFunctions.Binary(calc.getAns().intValue())); + } else { + + } q++; + } catch (Exception e) { + System.out.println("Sorry, bad input. Please enter a valid choice(number): "); + } + } while (q == 2); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java index a2733a38..c1ec693a 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -165,4 +165,13 @@ public static String fibonacci(Double input){ return str; } + public static String Hexadecimal(Integer input) { + return Integer.toHexString(input); + } + public static String Octal(Integer input) { + return Integer.toOctalString(input); + } + public static String Binary(Integer input) { + return Integer.toBinaryString(input); + } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/User.java b/src/main/java/com/zipcodewilmington/scientificcalculator/User.java index 9a37306e..a7db4808 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/User.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/User.java @@ -15,7 +15,5 @@ public Double getInputFromUser() { Double userInput = scanner.nextDouble(); return userInput; } - - } From 7f7e97ec91d7ff7a4d45d843cb0b48cc8b994bf3 Mon Sep 17 00:00:00 2001 From: Giles Bradford Date: Sun, 9 Feb 2020 18:08:29 -0500 Subject: [PATCH 27/29] updating to most recent version. --- .../scientificcalculator/Calculator.java | 74 ++----------------- .../scientificcalculator/MainApplication.java | 58 ++++++++------- .../ScientificFunctions.java | 2 +- 3 files changed, 37 insertions(+), 97 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java index 37048813..ba50c54c 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java @@ -7,7 +7,7 @@ public class Calculator { public Double firstOption; public Double secondOption; public Double ans; - public String stringAns; + public Double history; public Calculator() { @@ -22,6 +22,10 @@ public Double getAns() { return this.ans; } + public Double getCurrentValue(Double currentValue) { + return this.history; + } + public Double getInputFromUser() { Scanner scanner = new Scanner(System.in); Double userInput = scanner.nextDouble(); @@ -52,70 +56,4 @@ public Double getSecondNumber() { return secondOption; } -} - - - - - - - - - - - - - - - - - - - - - - - -/* -public class Calculator { - Double currentValue; - Double memory; - Double currentDisplay; - boolean appropriateInput; - Double answer; - - public Calculator(Double newCurrentValue) { - currentValue = newCurrentValue; - } - - public Double getCurrentValue() { - return currentValue; - } - - */ -/*public Double convertToDouble() { - String number1 = Double.parseDouble(); - return answer; - }*//* - - - public boolean checkIfAppropriate(boolean isAppropriate) { - if (appropriateInput) { - return appropriateInput; - } else { - return appropriateInput = false; - } - } - - */ -/*public getCurrentAnswer() { - - }*//* - - - public Double updateCurrentValue() { - currentValue = answer; - return currentValue; - } - -}*/ +} \ 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 8085caba..cc0c1dfb 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -5,20 +5,17 @@ public class MainApplication { public static void main(String[] args) { - /*//This allows us to use all methods from the 'Calculator.java' class. - - System.out.println("Please choose 'basic' or 'scientific' calculator: "); - //the method below calls the 'getInputFromUser' method on the 'calc' object created on line 9. - Double input = calc.getInputFromUser(); - //the below line calls the 'checkBasicsOrScience' method and stores the user input as 'newInput' - //because of the parameter that exists in the method. - calc.checkBasicOrScience(input);*/ + Double currentValue = 0.0; boolean t = true; while (t) { Calculator calc = new Calculator(); User user = new User(0.); ScientificFunctions func = new ScientificFunctions(); + // The lines below this were posibbly going to be used for getting the current value. I am still working on + // the idea as a whole. + //Double currentValue = calc.getAns(); + //System.out.println("Current Value: " + currentValue); int y = 2; @@ -57,9 +54,10 @@ public static void main(String[] args) { "16) tan\n" + "17) inverseCosine\n" + "18) inverseTangent\n" + - "19) radian\n" + - "20) factorial\n" + - "21) fibonacci\n"); + "19) inverseSine\n" + + "20) radian\n" + + "21) factorial\n" + + "22) fibonacci\n"); y = 1; } else { @@ -70,18 +68,8 @@ public static void main(String[] args) { } } while (y == 2); -//This is to error handle 1-4 =============== -/* int test = 2; - do { - try { - Double operator = calc.getInputFromUser(); - test = 1; - } catch (Exception e) { - System.out.println("Sorry, bad input"); - } - } while (test == 2);*/ - -// end process =================================== +/*We need to also error handle the options to pick the menus. We decided that these would not be done now and we + would save that for the absolute last issue. */ int test = 2; do { try { @@ -371,7 +359,7 @@ public static void main(String[] args) { System.out.println("Sorry, bad input"); } } while (x == 2); - Double ans = ScientificFunctions.radian(calc.getFirstNumber()); + Double ans = ScientificFunctions.inverseSine(calc.getFirstNumber()); calc.setAns(ans); } else if (operator.equals(20.)) { int x = 2; @@ -385,9 +373,23 @@ public static void main(String[] args) { System.out.println("Sorry, bad input"); } } while (x == 2); - Double ans = ScientificFunctions.factorial(calc.getFirstNumber()); + Double ans = ScientificFunctions.radian(calc.getFirstNumber()); calc.setAns(ans); } else if (operator.equals(21.)) { + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + Double ans = ScientificFunctions.factorial(calc.getFirstNumber()); + calc.setAns(ans); + } else if (operator.equals(22.)) { String ans = ScientificFunctions.fibonacci(calc.getFirstNumber()); } else { //System.out.println("Error"); @@ -397,9 +399,9 @@ public static void main(String[] args) { System.out.println("Sorry, bad input. Please enter a valid choice(number): "); } } while (test == 2); - System.out.println("Your answer is " + calc.getAns() + ""); + System.out.println("Your answer is " + calc.getAns() + ""); System.out.println("If you wish to convert your number to hexadecimal(1), Octal(2), or Binary(3), " + "please enter the corresponding number. You may also press 0 to reset the calculator."); int q = 2; @@ -417,8 +419,8 @@ else if (temp.equals(2.)) { else if (temp.equals(3.)) { System.out.println("Your Binary answer for " + calc.getAns() + " is " + ScientificFunctions.Binary(calc.getAns().intValue())); - } else { - + } else if (temp.equals(0.)){ + Runtime.getRuntime().exec("clear"); } q++; } catch (Exception e) { System.out.println("Sorry, bad input. Please enter a valid choice(number): "); diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java index c1ec693a..9efbe484 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -91,7 +91,7 @@ public static Double tangent(Double input){ return Math.tan(number); } // inverse sine - public Double inverseSine(Double input){ + public static Double inverseSine(Double input){ Double number = input; return Math.asin(number); } From b201c04c8b6a59c5e05911ccbd3e2ce0110a9c0d Mon Sep 17 00:00:00 2001 From: Jeremy McCray Date: Sun, 9 Feb 2020 20:49:14 -0500 Subject: [PATCH 28/29] fixed a few bugs but work still needs to be done to fix the memory and memory clearing --- .../scientificcalculator/Calculator.java | 11 ++++++++ .../scientificcalculator/MainApplication.java | 26 ++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java index ba50c54c..8337c259 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java @@ -8,11 +8,22 @@ public class Calculator { public Double secondOption; public Double ans; public Double history; + public Double calcChoice; public Calculator() { } + public Double setCalcChoice(Double choice) { + this.calcChoice = choice; + return choice; + } + + public Double getCalcChoice() { + return this.calcChoice; + } + + public Double setAns(Double ans) { this.ans = ans; return ans; diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index cc0c1dfb..d20e30af 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -74,11 +74,14 @@ public static void main(String[] args) { do { try { Double operator = calc.getInputFromUser(); + calc.setCalcChoice(operator); if (operator.equals(1.)) { int x = 2; + do { try { + System.out.println("Enter your first number"); Double firstNum = calc.getInputFromUser(); calc.setFirstInput(firstNum); @@ -390,7 +393,23 @@ public static void main(String[] args) { Double ans = ScientificFunctions.factorial(calc.getFirstNumber()); calc.setAns(ans); } else if (operator.equals(22.)) { - String ans = ScientificFunctions.fibonacci(calc.getFirstNumber()); + + int x = 2; + do { + try { + System.out.println("Enter your number"); + Double firstNum = calc.getInputFromUser(); + calc.setFirstInput(firstNum); + x = 1; + + System.out.println(ScientificFunctions.fibonacci(calc.getFirstNumber())); + } catch (Exception e) { + System.out.println("Sorry, bad input"); + } + } while (x == 2); + + + } else { //System.out.println("Error"); } @@ -400,8 +419,9 @@ public static void main(String[] args) { } } while (test == 2); - - System.out.println("Your answer is " + calc.getAns() + ""); + if (calc.getCalcChoice() <=21.) { + System.out.println("Your answer is " + calc.getAns() + ""); + } System.out.println("If you wish to convert your number to hexadecimal(1), Octal(2), or Binary(3), " + "please enter the corresponding number. You may also press 0 to reset the calculator."); int q = 2; From c7c2df0c6baa306ec75e9e8e1fa4f5aa9a847735 Mon Sep 17 00:00:00 2001 From: Giles Bradford Date: Mon, 10 Feb 2020 08:27:22 -0500 Subject: [PATCH 29/29] final commit --- .../scientificcalculator/MainApplication.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index d20e30af..c716570c 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -85,6 +85,8 @@ public static void main(String[] args) { System.out.println("Enter your first number"); Double firstNum = calc.getInputFromUser(); calc.setFirstInput(firstNum); + String storedFirstNum = calc.getFirstNumber().toString(); + System.out.println("Enter your Second Number"); Double secondNum = calc.getInputFromUser(); calc.setSecondOptionInput(secondNum); @@ -419,11 +421,12 @@ public static void main(String[] args) { } } while (test == 2); - if (calc.getCalcChoice() <=21.) { + if (calc.getCalcChoice() <= 21.) { System.out.println("Your answer is " + calc.getAns() + ""); - } + System.out.println("If you wish to convert your number to hexadecimal(1), Octal(2), or Binary(3), " + "please enter the corresponding number. You may also press 0 to reset the calculator."); + } int q = 2; do { try {