Skip to content
Snippets Groups Projects
Commit 1f8a5bd5 authored by PIERRON Laurent's avatar PIERRON Laurent :man_in_tuxedo_tone1:
Browse files

Remplacement des String par des constantes, amélioration du case.

parent 5449e4c7
No related branches found
No related tags found
No related merge requests found
package fr.nancy.iut; package fr.nancy.iut;
/** /**
* The main part of the calculator performing the * The main part of the calculator doing the calculations.
* arithmetic logic of the calculations. *
* @author Hacker T. Largebrain * @author David J. Barnes and Michael Kölling
* @version 1.0 * @version 2011.07.31
*/ */
public class CalcEngine public class CalcEngine
{ {
static final String TITLE = "Super Calculator";
static final String AUTHOR = "Branes & Kölling";
static final String VERSION = "2.0.1";
// The calculator's state is maintained in three fields: // The calculator's state is maintained in three fields:
// buildingDisplayValue, haveLeftOperand, and lastOperator. // buildingDisplayValue, haveLeftOperand, and lastOperator.
...@@ -82,7 +86,7 @@ public class CalcEngine ...@@ -82,7 +86,7 @@ public class CalcEngine
*/ */
public void equals() public void equals()
{ {
// This should completes the building of a second operand, // This should complete the building of a second operand,
// so ensure that we really have a left operand, an operator // so ensure that we really have a left operand, an operator
// and a right operand. // and a right operand.
if(haveLeftOperand && if(haveLeftOperand &&
...@@ -114,7 +118,7 @@ public class CalcEngine ...@@ -114,7 +118,7 @@ public class CalcEngine
*/ */
public String getTitle() public String getTitle()
{ {
return "Super Calculator"; return TITLE;
} }
/** /**
...@@ -122,7 +126,7 @@ public class CalcEngine ...@@ -122,7 +126,7 @@ public class CalcEngine
*/ */
public String getAuthor() public String getAuthor()
{ {
return "Hacker T. Largebrain"; return AUTHOR;
} }
/** /**
...@@ -130,7 +134,7 @@ public class CalcEngine ...@@ -130,7 +134,7 @@ public class CalcEngine
*/ */
public String getVersion() public String getVersion()
{ {
return "version 0.2"; return VERSION;
} }
/** /**
...@@ -141,20 +145,18 @@ public class CalcEngine ...@@ -141,20 +145,18 @@ public class CalcEngine
*/ */
private void calculateResult() private void calculateResult()
{ {
switch(lastOperator) { switch (lastOperator) {
case '+': case '+' -> {
displayValue = leftOperand + displayValue; displayValue = leftOperand + displayValue;
haveLeftOperand = true; haveLeftOperand = true;
leftOperand = displayValue; leftOperand = displayValue;
break; }
case '-': case '-' -> {
displayValue = leftOperand - displayValue; displayValue = leftOperand - displayValue;
haveLeftOperand = true; haveLeftOperand = true;
leftOperand = displayValue; leftOperand = displayValue;
break; }
default: default -> keySequenceError();
keySequenceError();
break;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment