Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Formula
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RADELLAH Badr
Formula
Commits
ad925775
Commit
ad925775
authored
9 months ago
by
RADELLAH Badr
Browse files
Options
Downloads
Patches
Plain Diff
q2 TP2
parent
a280837f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/formula/Product.java
+20
-5
20 additions, 5 deletions
src/main/java/formula/Product.java
src/main/java/formula/Sum.java
+19
-5
19 additions, 5 deletions
src/main/java/formula/Sum.java
with
39 additions
and
10 deletions
src/main/java/formula/Product.java
+
20
−
5
View file @
ad925775
...
@@ -3,17 +3,26 @@ package formula;
...
@@ -3,17 +3,26 @@ package formula;
public
class
Product
implements
Formula
{
public
class
Product
implements
Formula
{
private
Formula
[]
formulas
;
private
Formula
[]
formulas
;
// Constructeur prenant un tableau de formules
public
Product
(
Formula
...
formulas
)
{
public
Product
(
Formula
...
formulas
)
{
this
.
formulas
=
formulas
;
this
.
formulas
=
formulas
;
}
}
// Retourne la valeur initiale pour le produit (1)
public
double
initialValue
()
{
return
1
;
}
// Cumul des valeurs pour le produit (multiplication)
public
double
cumulativeValue
(
double
accumulator
,
double
value
)
{
return
accumulator
*
value
;
}
@Override
@Override
public
String
asString
()
{
public
String
asString
()
{
StringBuilder
sb
=
new
StringBuilder
(
"("
);
StringBuilder
sb
=
new
StringBuilder
(
"("
);
for
(
int
i
=
0
;
i
<
formulas
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
formulas
.
length
;
i
++)
{
sb
.
append
(
formulas
[
i
].
asString
());
sb
.
append
(
formulas
[
i
].
asString
());
if
(
i
<
formulas
.
length
-
1
)
sb
.
append
(
"*"
);
// Ajouter un "*" entre les formules
if
(
i
<
formulas
.
length
-
1
)
sb
.
append
(
symbol
());
}
}
sb
.
append
(
")"
);
sb
.
append
(
")"
);
return
sb
.
toString
();
return
sb
.
toString
();
...
@@ -21,10 +30,16 @@ public class Product implements Formula {
...
@@ -21,10 +30,16 @@ public class Product implements Formula {
@Override
@Override
public
double
asValue
()
{
public
double
asValue
()
{
double
p
roduct
=
1
;
double
result
=
initialValue
();
// Initialise avec la valeur de départ (1 pour P
roduct
)
for
(
Formula
formula
:
formulas
)
{
for
(
Formula
formula
:
formulas
)
{
produc
t
*
=
formula
.
asValue
();
resul
t
=
cumulativeValue
(
result
,
formula
.
asValue
());
// Multiplie chaque valeur
}
}
return
product
;
return
result
;
}
// Méthode symbol() comme déjà définie
public
String
symbol
()
{
return
"*"
;
}
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/formula/Sum.java
+
19
−
5
View file @
ad925775
...
@@ -3,17 +3,26 @@ package formula;
...
@@ -3,17 +3,26 @@ package formula;
public
class
Sum
implements
Formula
{
public
class
Sum
implements
Formula
{
private
Formula
[]
formulas
;
private
Formula
[]
formulas
;
// Constructeur prenant un tableau de formules
public
Sum
(
Formula
...
formulas
)
{
public
Sum
(
Formula
...
formulas
)
{
this
.
formulas
=
formulas
;
this
.
formulas
=
formulas
;
}
}
// Retourne la valeur initiale pour la somme (0)
public
double
initialValue
()
{
return
0
;
}
// Cumul des valeurs pour la somme (addition)
public
double
cumulativeValue
(
double
accumulator
,
double
value
)
{
return
accumulator
+
value
;
}
@Override
@Override
public
String
asString
()
{
public
String
asString
()
{
StringBuilder
sb
=
new
StringBuilder
(
"("
);
StringBuilder
sb
=
new
StringBuilder
(
"("
);
for
(
int
i
=
0
;
i
<
formulas
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
formulas
.
length
;
i
++)
{
sb
.
append
(
formulas
[
i
].
asString
());
sb
.
append
(
formulas
[
i
].
asString
());
if
(
i
<
formulas
.
length
-
1
)
sb
.
append
(
"+"
);
// Ajouter un "+" entre les formules
if
(
i
<
formulas
.
length
-
1
)
sb
.
append
(
symbol
());
}
}
sb
.
append
(
")"
);
sb
.
append
(
")"
);
return
sb
.
toString
();
return
sb
.
toString
();
...
@@ -21,10 +30,15 @@ public class Sum implements Formula {
...
@@ -21,10 +30,15 @@ public class Sum implements Formula {
@Override
@Override
public
double
asValue
()
{
public
double
asValue
()
{
double
sum
=
0
;
double
result
=
initialValue
();
// Initialise avec la valeur de départ (0 pour Sum)
for
(
Formula
formula
:
formulas
)
{
for
(
Formula
formula
:
formulas
)
{
sum
+=
formula
.
asValue
();
result
=
cumulativeValue
(
result
,
formula
.
asValue
());
// Ajoute chaque valeur
}
return
result
;
}
}
return
sum
;
// Méthode symbol() comme déjà définie
public
String
symbol
()
{
return
"+"
;
}
}
}
}
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