-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f864adb
commit 5ef25fd
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package helper; | ||
|
||
public interface DistanceCalculator { | ||
void add(double a, double b); | ||
double calculate(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package helper; | ||
|
||
public interface MeanCalculator { | ||
void add(double a); | ||
double calculate(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package helper.impl; | ||
|
||
import helper.DistanceCalculator; | ||
|
||
public class EuklidesDistanceCalculator implements DistanceCalculator { | ||
|
||
double sumBeforeSquare = 0; | ||
|
||
@Override | ||
public void add(double a, double b) { | ||
sumBeforeSquare += Math.pow(a-b, 2); | ||
} | ||
|
||
@Override | ||
public double calculate() { | ||
double euklidesDistance = Math.sqrt(sumBeforeSquare); | ||
|
||
sumBeforeSquare = 0; | ||
|
||
return euklidesDistance; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package helper.impl; | ||
|
||
import helper.MeanCalculator; | ||
|
||
public class MeanCalaculatorImpl implements MeanCalculator { | ||
|
||
double currentSum = 0; | ||
int numberOfItems = 0; | ||
|
||
@Override | ||
public void add(double a) { | ||
currentSum += a; | ||
numberOfItems++; | ||
} | ||
|
||
@Override | ||
public double calculate() { | ||
double calculatedMean = currentSum/numberOfItems; | ||
|
||
currentSum = 0; | ||
numberOfItems = 0; | ||
|
||
return calculatedMean; | ||
} | ||
|
||
} |