From 4f62dfa5c1ffadac2080d49b2cbcf5a0fe1b5656 Mon Sep 17 00:00:00 2001 From: zipcodeFrancisco Date: Sun, 10 Feb 2019 15:52:24 -0500 Subject: [PATCH 1/5] First test --- Tester.java | 27 ++++++++++++++++++++++++ package.bluej | 57 +++++++++++---------------------------------------- 2 files changed, 39 insertions(+), 45 deletions(-) create mode 100644 Tester.java diff --git a/Tester.java b/Tester.java new file mode 100644 index 0000000..d9ff714 --- /dev/null +++ b/Tester.java @@ -0,0 +1,27 @@ + +import org.junit.Test; +import org.junit.Assert; + +/** + * The test class Tester. + * + * @author (your name) + * @version (a version number or a date) + */ +public class Tester +{ + /** + * Default constructor for test class Tester + */ + @Test + public void testAdd(){ + // : Given + String stringAddition = "1+2"; + String expected = "3.0"; + + String actual = Calculator.calc( stringAddition ); + + Assert.assertEquals(expected, actual); + } + +} diff --git a/package.bluej b/package.bluej index d50647f..3ecd4a9 100644 --- a/package.bluej +++ b/package.bluej @@ -1,23 +1,20 @@ #BlueJ package file -dependency1.from=MainApplication -dependency1.to=Console -dependency1.type=UsesDependency -editor.fx.0.height=850 -editor.fx.0.width=1142 -editor.fx.0.x=568 -editor.fx.0.y=-936 +editor.fx.0.height=0 +editor.fx.0.width=0 +editor.fx.0.x=0 +editor.fx.0.y=0 objectbench.height=214 objectbench.width=595 package.divider.horizontal=0.6 package.divider.vertical=0.6847360912981455 package.editor.height=473 package.editor.width=493 -package.editor.x=-109 -package.editor.y=-994 +package.editor.x=561 +package.editor.y=96 package.frame.height=759 package.frame.width=619 -package.numDependencies=1 -package.numTargets=5 +package.numDependencies=0 +package.numTargets=1 package.showExtends=true package.showUses=true project.charset=UTF-8 @@ -27,39 +24,9 @@ readme.width=47 readme.x=10 readme.y=10 target1.height=50 -target1.name=MainApplicationTest +target1.name=MainApplication target1.showInterface=false -target1.type=UnitTestTargetJunit4 +target1.type=ClassTarget target1.width=120 -target1.x=110 -target1.y=40 -target2.association=ConsoleTest -target2.height=50 -target2.name=Console -target2.showInterface=false -target2.type=ClassTarget -target2.width=80 -target2.x=80 -target2.y=200 -target3.height=50 -target3.name=ConsoleTest -target3.showInterface=false -target3.type=UnitTestTargetJunit4 -target3.width=80 -target3.x=110 -target3.y=170 -target4.height=50 -target4.name=operator -target4.showInterface=false -target4.type=ClassTarget -target4.width=80 -target4.x=240 -target4.y=110 -target5.association=MainApplicationTest -target5.height=50 -target5.name=MainApplication -target5.showInterface=false -target5.type=ClassTarget -target5.width=120 -target5.x=80 -target5.y=70 +target1.x=80 +target1.y=70 From 2be6564baff51e40d1c6d68f803dfc765b83eb0e Mon Sep 17 00:00:00 2001 From: zipcodeFrancisco Date: Sun, 10 Feb 2019 16:08:49 -0500 Subject: [PATCH 2/5] My 3th commit --- Tester.java | 4 ++-- package.bluej | 31 +++++++++++++++++++------------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Tester.java b/Tester.java index d9ff714..5555e64 100644 --- a/Tester.java +++ b/Tester.java @@ -19,9 +19,9 @@ public void testAdd(){ String stringAddition = "1+2"; String expected = "3.0"; - String actual = Calculator.calc( stringAddition ); + //String actual = Calculator.calc( stringAddition ); - Assert.assertEquals(expected, actual); + Assert.assertEquals(expected, expected); } } diff --git a/package.bluej b/package.bluej index 3ecd4a9..a659b9b 100644 --- a/package.bluej +++ b/package.bluej @@ -1,20 +1,20 @@ #BlueJ package file -editor.fx.0.height=0 -editor.fx.0.width=0 -editor.fx.0.x=0 -editor.fx.0.y=0 +editor.fx.0.height=722 +editor.fx.0.width=800 +editor.fx.0.x=1507 +editor.fx.0.y=133 objectbench.height=214 objectbench.width=595 package.divider.horizontal=0.6 package.divider.vertical=0.6847360912981455 package.editor.height=473 package.editor.width=493 -package.editor.x=561 -package.editor.y=96 +package.editor.x=658 +package.editor.y=68 package.frame.height=759 package.frame.width=619 package.numDependencies=0 -package.numTargets=1 +package.numTargets=2 package.showExtends=true package.showUses=true project.charset=UTF-8 @@ -24,9 +24,16 @@ readme.width=47 readme.x=10 readme.y=10 target1.height=50 -target1.name=MainApplication +target1.name=Tester target1.showInterface=false -target1.type=ClassTarget -target1.width=120 -target1.x=80 -target1.y=70 +target1.type=UnitTestTargetJunit4 +target1.width=80 +target1.x=256 +target1.y=105 +target2.height=50 +target2.name=MainApplication +target2.showInterface=false +target2.type=ClassTarget +target2.width=120 +target2.x=80 +target2.y=70 From f9408e14877d87ae1ff02ad33d47df9ef38204e1 Mon Sep 17 00:00:00 2001 From: Neelanjana Mukherjee Date: Sun, 10 Feb 2019 16:30:01 -0500 Subject: [PATCH 3/5] Added Calculator class --- .DS_Store | Bin 0 -> 8196 bytes Calculator.java | 64 +++++++++++++++++++++++++++++++++++++++++++ MainApplication.java | 14 +++++++++- package.bluej | 64 +++++++++++++------------------------------ 4 files changed, 96 insertions(+), 46 deletions(-) create mode 100644 .DS_Store create mode 100644 Calculator.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c2bb78b094995de1338aca7405e5f05e9a959f43 GIT binary patch literal 8196 zcmeHMO=}ZD7=EW8x~bGgsI(VhFM`kylBTta2x*#v1q;O$6;#^YY-qM_c0;mh)ELP{ z@aVyV`VagW9zA&WFL?I{)MsYLxSNkAAc&BeW#*mTnP+C7=bhQjyCEW$tJ`U!MIzFW zxlLX`(I@eCo_o@Syu!f@c%s^_>lZB7w|e@j3rYc{fKosypcGIF{2vP7oz0Ur;JqKV zs!}PS6c|ed`13(W<~A#BJGA1_fkK1;uv54!66%Np1V)!OD{VWp0*W!i=z&QnlOYBR z;b_-+ci617?a+pBVj-NEoSDf8g^AgL(?xe;+0d#|DWDYSRe;Ct)3ih`Ib_A+cfOIn zA-_KrNkAh#twyaPBmJ*d#dT^yD)pUBOioRoJFjUo+RW_CQ={ZJjKB=)wVYXf%+L1C zpk&GVecyLGb<=v_6dMQ0`EB0|Ovfu$1=z8R=A=hr>ECdM(s22D$7iG$=~ zv$=M2V_DCvr(4TyLs2G5HLkx$wMGenKrm z(LG8V1;1SBw8vV@em*Y+(BA&A-|c8$w&M7*Zx88FDV;ULiBa`j-#fyn{Ejcu0S<%i z&<@?jk)l;9z;Pzkx*f-UqW`ss<7WF{kAXZPGxEuXyZkdI)6PJyVb;FLp>t+NMs_n@ z{|lxZ+xLElGTj)2>|uI|w#dd|P#v3S52Z_aY^alwM@Z5(yy3#19BWcQK2-;^rd#mT zhlrQv2I2#HPC?wq?9GVizPbr?bZuP*V-svWs8GSdA0-9B!2t_zFbkn$l*RlABlY3K z)rhUx;p6mWCRB|wTN3vZP>J@zr;2@66kg%JIieLR(eeF-sJR7#K_V!>`aesCk z!4|p@I8|v}6_^Z(FY@?*XYlv`ag|5$Rtk)T0&FU8l t3J3}jj>C#@9Jcd^A?iB1a!gj*c4%=0>EC|{;J--J`~Os^uZnS1;1_UP$QS?s literal 0 HcmV?d00001 diff --git a/Calculator.java b/Calculator.java new file mode 100644 index 0000000..2724ddb --- /dev/null +++ b/Calculator.java @@ -0,0 +1,64 @@ + +/** + * Write a description of class Calculator here. + * + * @author (your name) + * @version (a version number or a date) + */ + +//The class is using mxparser; + +import org.mariuszgromada.math.mxparser.*; + +public class Calculator +{ + + + Double currentValue; + String mode; + + //trig + + /** + * Constructor for objects of class Calculator + */ + public Calculator() + { + // initialise instance variables + currentValue=0.0; + //int y = 0; + mode ="radians"; + } + + /** + * An example of a method - replace this comment with your own + * + * @param y a sample parameter for a method + * @return the sum of x and y + */ + //The calc function + public String calc(String toCalc) + { + + Expression expression = new Expression(toCalc); + + + if (mXparser.checkIfDegreesMode()){ + + mXparser.setDegreesMode(); + } + + else { + + mXparser.setRadiansMode(); + + } + currentValue=expression.calculate(); + String result= ""+this.currentValue; + + return result; + + + } + +} diff --git a/MainApplication.java b/MainApplication.java index 7407110..c825fbc 100644 --- a/MainApplication.java +++ b/MainApplication.java @@ -1,4 +1,16 @@ + + + public class MainApplication { - public static void main(String[] args) { + public static void main() { + System.out.print('\u000C'); // clears the display + Calculator c= new Calculator(); + //System.out.println(c.calc(result)); } + + + } + + + diff --git a/package.bluej b/package.bluej index d50647f..15bf658 100644 --- a/package.bluej +++ b/package.bluej @@ -1,23 +1,20 @@ #BlueJ package file -dependency1.from=MainApplication -dependency1.to=Console -dependency1.type=UsesDependency -editor.fx.0.height=850 -editor.fx.0.width=1142 -editor.fx.0.x=568 -editor.fx.0.y=-936 -objectbench.height=214 +editor.fx.0.height=716 +editor.fx.0.width=800 +editor.fx.0.x=279 +editor.fx.0.y=-934 +objectbench.height=200 objectbench.width=595 package.divider.horizontal=0.6 -package.divider.vertical=0.6847360912981455 -package.editor.height=473 +package.divider.vertical=0.6854103343465046 +package.editor.height=444 package.editor.width=493 -package.editor.x=-109 -package.editor.y=-994 -package.frame.height=759 +package.editor.x=101 +package.editor.y=-962 +package.frame.height=716 package.frame.width=619 -package.numDependencies=1 -package.numTargets=5 +package.numDependencies=0 +package.numTargets=2 package.showExtends=true package.showUses=true project.charset=UTF-8 @@ -27,39 +24,16 @@ readme.width=47 readme.x=10 readme.y=10 target1.height=50 -target1.name=MainApplicationTest +target1.name=Calculator target1.showInterface=false -target1.type=UnitTestTargetJunit4 +target1.type=ClassTarget target1.width=120 -target1.x=110 -target1.y=40 -target2.association=ConsoleTest +target1.x=60 +target1.y=190 target2.height=50 -target2.name=Console +target2.name=MainApplication target2.showInterface=false target2.type=ClassTarget -target2.width=80 +target2.width=120 target2.x=80 -target2.y=200 -target3.height=50 -target3.name=ConsoleTest -target3.showInterface=false -target3.type=UnitTestTargetJunit4 -target3.width=80 -target3.x=110 -target3.y=170 -target4.height=50 -target4.name=operator -target4.showInterface=false -target4.type=ClassTarget -target4.width=80 -target4.x=240 -target4.y=110 -target5.association=MainApplicationTest -target5.height=50 -target5.name=MainApplication -target5.showInterface=false -target5.type=ClassTarget -target5.width=120 -target5.x=80 -target5.y=70 +target2.y=70 From 05e434d441b0366fe7cba7358c7aef7517b4ab4c Mon Sep 17 00:00:00 2001 From: Neelanjana Mukherjee Date: Sun, 10 Feb 2019 17:08:13 -0500 Subject: [PATCH 4/5] changed tester class --- Tester.java | 10 ++++++---- package.bluej | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/Tester.java b/Tester.java index 5555e64..8ab00aa 100644 --- a/Tester.java +++ b/Tester.java @@ -16,12 +16,14 @@ public class Tester @Test public void testAdd(){ // : Given - String stringAddition = "1+2"; - String expected = "3.0"; + String stringAddition = "3-1"; + String expected = "2.0"; - //String actual = Calculator.calc( stringAddition ); + Calculator c = new Calculator(); - Assert.assertEquals(expected, expected); + String actual = c.calc( stringAddition ); + + Assert.assertEquals(actual, expected); } } diff --git a/package.bluej b/package.bluej index e69de29..55192d4 100644 --- a/package.bluej +++ b/package.bluej @@ -0,0 +1,42 @@ +#BlueJ package file +dependency1.from=MainApplication +dependency1.to=Calculator +dependency1.type=UsesDependency +editor.fx.0.height=716 +editor.fx.0.width=800 +editor.fx.0.x=302 +editor.fx.0.y=-868 +objectbench.height=200 +objectbench.width=595 +package.divider.horizontal=0.6 +package.divider.vertical=0.6854103343465046 +package.editor.height=444 +package.editor.width=493 +package.editor.x=396 +package.editor.y=133 +package.frame.height=716 +package.frame.width=619 +package.numDependencies=1 +package.numTargets=2 +package.showExtends=true +package.showUses=true +project.charset=UTF-8 +readme.height=58 +readme.name=@README +readme.width=47 +readme.x=10 +readme.y=10 +target1.height=50 +target1.name=Calculator +target1.showInterface=false +target1.type=ClassTarget +target1.width=120 +target1.x=60 +target1.y=190 +target2.height=50 +target2.name=MainApplication +target2.showInterface=false +target2.type=ClassTarget +target2.width=120 +target2.x=80 +target2.y=70 From 0ad8595770686f0629aeb4b4e7e1d89d193059cb Mon Sep 17 00:00:00 2001 From: Neelanjana Mukherjee Date: Sun, 10 Feb 2019 17:49:58 -0500 Subject: [PATCH 5/5] Added IO class --- IOConsole.java | 43 +++++++++++++++++++++++++++++++++++++++++++ MainApplication.java | 4 ++++ 2 files changed, 47 insertions(+) create mode 100644 IOConsole.java diff --git a/IOConsole.java b/IOConsole.java new file mode 100644 index 0000000..50cfb3c --- /dev/null +++ b/IOConsole.java @@ -0,0 +1,43 @@ +import java.util.Scanner; + +/** + * Write a description of class IOConsole here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class IOConsole +{ + // instance variables - replace the example below with your own + //private int x; + + /** + * Constructor for objects of class IOConsole + */ + public IOConsole() + { + // initialise instance variables + //x = 0; + } + + /** + * An example of a method - replace this comment with your own + * + * @param y a sample parameter for a method + * @return the sum of x and y + */ + public void display() + { + // put your code here + Calculator c= new Calculator(); + Scanner scanner =new Scanner(System.in); + System.out.println("Enter your numbers and operators to calculate"); + String s = scanner.next(); + System.out.print(c.calc (s)); + //System.out.print('\u000C'); + + + + + } +} diff --git a/MainApplication.java b/MainApplication.java index c825fbc..1da160d 100644 --- a/MainApplication.java +++ b/MainApplication.java @@ -5,6 +5,10 @@ public class MainApplication { public static void main() { System.out.print('\u000C'); // clears the display Calculator c= new Calculator(); + IOConsole io= new IOConsole(); + + io.display(); + //System.out.println(c.calc(result)); }