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
92 changes: 92 additions & 0 deletions Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
public class Application {

public Application() {

}

public static void main(String[] args) {
run();
}

public static void run() {
IOConsole console = new IOConsole();
Processor processor = new Processor();
String result = "";
String numConvert = "";


boolean quit = false;
// Hello
console.println("Hi!");
while(!quit) {

// String input = console.getStringInput("Would you like to change the display?");
// if (input.matches("yes")){
// String viewDisplayinput = console.getStringInput("Would you like to view display options");
// if(viewDisplayinput.matches("yes")) {
// processor.displayMode("display");
// } else {
// String mode = console.getStringInput("Enter Mode:");
// processor.displayMode(mode);
// Integer x = console.getIntegerInput("Enter x");
// numConvert = processor.changeMode(mode, x);
// console.println(numConvert);
// // enter y
// Integer y = console.getIntegerInput("Enter y");
// numConvert = processor.changeMode(mode, y);
// console.println(numConvert);
// }
// }


// enter operator
String operator = console.getStringInput("Enter operator");

boolean isValid = isValid(operator);
if(!isValid) {
run();
} else {
if(operator.matches("inverse|square|invert|!|sqrt|sin|asin|cos|acos|tan|atan|")){
Double x = console.getDoubleInput("Enter x");
result = processor.arithmetic(operator, x, 0.0);
} else {
// enter x
Double x = console.getDoubleInput("Enter x");
// enter y
Double y = console.getDoubleInput("Enter y");
result = processor.arithmetic(operator, x, y);
}

}
// print result
console.println(result);

console.println("Would you like to do more Math????");
console.println("Enter: yes to continue.");
String redo = console.getStringInput("Enter: no to quit.");

// More math?
if(redo.equals("no")) {
quit = true;
} else {
console.clearScreen();
quit = false;
}


}
// bye!
}
public static boolean isValid(String operation) {
String[] operations = {"-", "/", "*", "^", "+" , "inverse" , "square" , "invert" , "!" , "sqrt", "sin" , "asin" , "cos" , "acos" , "tan" , "atan"};
for(int i= 0; i < operations.length-1; i++) {
if(operations[i].equals(operation)) {
return true;
}
}
return false;
}


}

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


import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
* The test class ApplicationTest.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ApplicationTest
{
/**
* Default constructor for test class ApplicationTest
*/
public ApplicationTest()
{
}

/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
@Before
public void setUp()
{
}

/**
* Tears down the test fixture.
*
* Called after every test case method.
*/
@After
public void tearDown()
{
}
}
166 changes: 166 additions & 0 deletions Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@

/**
* Write a description of class Calculator here.
*
* @author (your name)
* @version (a version number or a date)
*/

import java.lang.Math;

public class Calculator
{
// instance variables - replace the example below with your own
private Double x;

/**
* Constructor for objects of class Calculator
*/
public Calculator()
{
// initialise instance variables
x = 0.0;
}


/**
* TODO Write comments
*/
public Double squareMethod(Double x)
{
// put your code here
return x * x;

}

public Double add(Double x,Double y)
{
return (x+y);
}

public Double sub(Double x,Double y)
{
return x - y;
}

public Double multiply(Double x,Double y)
{
return (x*y);
}

public Double div(Double x,Double y)
{
return (Double)(x/y);
}
public Double squareRootMethod(Double x)
{
// put your code here
return Math.sqrt(x);

}

public Double invertMethod(Double x)
{
// put your code here
x=-x;
return x;

}
public Double exponentiationMethod(Double x,Double y)
{
// put your code here
return Math.pow(x,y);

}

public Double inverseMethod(Double x)
{
// put your code here
return 1/(Double)x;

}

public Double sineMathMethod(Double x)
{
Double radians = Math.toRadians(x);


return (Math.sin(radians));

}

public Double cosMathMethod(Double x)

{
Double radians = Math.toRadians(x);
// put your code here
return (Math.cos(radians));

}

public Double tanMathMethod(Double x)
{
Double radians = Math.toRadians(x);
// put your code here
return (Math.tan(radians));

}
public Double invSineMathMethod(Double x)
{
//Double radians = Math.toRadians(x);

return (Math.asin(x));

}

public Double invCosMathMethod(Double x)
{
Double radians = Math.toRadians(x);
// put your code here
return (Math.acos(radians));

}

public Double invTanMathMethod(Double x)
{
//Double radians = Math.toRadians(x);
// put your code here
return (Math.atan(x));

}

public long factorialMethod(Double x){

long result = 1;

for (int factor = 2; factor <= x; factor++) {
result *= factor;
}

return result;
}

public String toBinary(int x)
{
String binary =Integer.toBinaryString( x );
return binary;
}

public String toOctal(int x)
{
String octal =Integer.toOctalString( x );
return octal;
}

/*public String tofloat (int x)
{
String fl =Integer.floatValue( x );
return fl;
}
*/
public String toHexadecimal(int x)
{
String hexa =Integer.toHexString( x );
return hexa;
}
}
Loading