Skip to content

Commit

Permalink
Update master branch to v0.3.0 (#3)
Browse files Browse the repository at this point in the history
* User now knows if stack is empty

* Update version number to match the current development branch

* Implement modulo and power operators

* Update version number since it's ready to be merged
  • Loading branch information
AntoineJT authored May 3, 2019
1 parent acf9ce8 commit 189d23e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/com/github/antoinejt/jasc/ConsoleUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ private static void displayHelp(){
"+ : Addition operator",
"- : Substraction operator",
"* : Multiplication operator",
"/ : Division operator").print();
"/ : Division operator",
"% : Modulo operator",
"^ : Power operator").print();
TextFormat.listThings("Available functions (acts on 1 operand) : ",
"sqrt : Perform a square root",
"log : Perform a decimal logarithm",
Expand Down Expand Up @@ -49,6 +51,15 @@ private static void displayIntro(){
"To know available commands, you can type help");
}

private static void printStackContent(CalculatorEngine calculatorEngine) {
List list = calculatorEngine.getNumbers();
if (list.size() > 0){
list.forEach(System.out::println);
} else {
System.err.println("Stack is empty!");
}
}

public static void useConsole() throws Exception {
displayIntro();
CalculatorEngine calculatorEngine = new CalculatorEngine();
Expand All @@ -57,7 +68,7 @@ public static void useConsole() throws Exception {
while (true){
input = scanner.next();
List<String> commands = Arrays.asList(
"+", "-", "*", "/", // Operators
"+", "-", "*", "/", "%", "^", // Operators
"sqrt", "log", "ln", "lb", "cos", "sin", "tan", "arccos", "arcsin", "arctan", "exp", // Functions
"=", "help", "clear", "quit" // Commands
);
Expand All @@ -75,6 +86,8 @@ public static void useConsole() throws Exception {
operators.put("-", OperationType.SUBSTRACTION);
operators.put("*", OperationType.MULTIPLICATION);
operators.put("/", OperationType.DIVISION);
operators.put("%", OperationType.MODULO);
operators.put("^", OperationType.POWER);

if (operators.containsKey(input)){
try {
Expand All @@ -85,7 +98,7 @@ public static void useConsole() throws Exception {
} else {
boolean isFunction = false;
switch(input){
case "=": calculatorEngine.getNumbers().forEach(System.out::println); break;
case "=": printStackContent(calculatorEngine); break;
case "help": displayHelp(); break;
case "clear": calculatorEngine.clear(); break;
case "quit": System.exit(0);
Expand Down
2 changes: 1 addition & 1 deletion src/com/github/antoinejt/jasc/Constants.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.antoinejt.jasc;

final class Constants {
static final String VERSION = "0.2.2";
static final String VERSION = "0.3.0";
static final String LAST_UPDATE = "May 3rd 2019";
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public void operate(OperationType operation) throws ArithmeticException, Operand
case SUBSTRACTION: calc = operand[1] - operand[0]; break;
case MULTIPLICATION: calc = operand[1] * operand[0]; break;
case DIVISION: calc = operand[1] / operand[0]; break;
case MODULO: calc = operand[1] % operand[0]; break;
case POWER: calc = Double.valueOf(Math.pow(operand[1], operand[0])).floatValue(); break;
default: throw new CalculatorException("The provided operation is not handled!");
}
// I can't imagine how this can happened
Expand Down
4 changes: 3 additions & 1 deletion src/com/github/antoinejt/jasc/calculator/OperationType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ public enum OperationType {
ADDITION,
SUBSTRACTION,
MULTIPLICATION,
DIVISION
DIVISION,
MODULO,
POWER
}

0 comments on commit 189d23e

Please sign in to comment.