Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
64 changes: 64 additions & 0 deletions Calculator.java
Original file line number Diff line number Diff line change
@@ -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;


}

}
43 changes: 43 additions & 0 deletions IOConsole.java
Original file line number Diff line number Diff line change
@@ -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');




}
}
18 changes: 17 additions & 1 deletion MainApplication.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@



public class MainApplication {
public static void main(String[] args) {
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));
}



}



29 changes: 29 additions & 0 deletions Tester.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

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 = "3-1";
String expected = "2.0";

Calculator c = new Calculator();

String actual = c.calc( stringAddition );

Assert.assertEquals(actual, expected);
}

}
61 changes: 19 additions & 42 deletions package.bluej
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#BlueJ package file
dependency1.from=MainApplication
dependency1.to=Console
dependency1.to=Calculator
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=302
editor.fx.0.y=-868
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=396
package.editor.y=133
package.frame.height=716
package.frame.width=619
package.numDependencies=1
package.numTargets=5
package.numTargets=2
package.showExtends=true
package.showUses=true
project.charset=UTF-8
Expand All @@ -27,39 +27,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