Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
calculator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PIERRON Laurent
calculator
Commits
1f8a5bd5
Commit
1f8a5bd5
authored
2 years ago
by
PIERRON Laurent
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/fr/nancy/iut/CalcEngine.java
+18
-16
18 additions, 16 deletions
src/main/java/fr/nancy/iut/CalcEngine.java
with
18 additions
and
16 deletions
src/main/java/fr/nancy/iut/CalcEngine.java
+
18
−
16
View file @
1f8a5bd5
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
.
L
ar
gebra
in
* @author
David J
.
B
ar
nes and Michael Köll
in
g
* @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 complete
s
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
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment