diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
new file mode 100644
index 0000000..3384681
--- /dev/null
+++ b/.github/workflows/maven.yml
@@ -0,0 +1,26 @@
+# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
+# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
+
+name: Java CI with Maven
+
+on:
+ push:
+ branches: [ main ]
+ pull_request:
+ branches: [ main ]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up JDK 17
+ uses: actions/setup-java@v2
+ with:
+ java-version: '17'
+ distribution: 'temurin'
+ cache: maven
+ - name: Build with Maven
+ run: mvn -B package --file pom.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 9a536f5..e0991c0 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -7,6 +7,7 @@
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index d31b37a..67e1e61 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -8,5 +8,5 @@
-
+
\ No newline at end of file
diff --git a/src/main/java/edu/bristol/IMDBRating.java b/src/main/java/edu/bristol/IMDBRating.java
index 6021d63..d3dbfa3 100644
--- a/src/main/java/edu/bristol/IMDBRating.java
+++ b/src/main/java/edu/bristol/IMDBRating.java
@@ -7,8 +7,11 @@ public class IMDBRating
public float addNewRating(int newRating)
{
- int previousTotal = (int) (currentAverage * ratingCount);
- int newTotal = previousTotal + newRating;
+ if(newRating>10 || newRating<0) {
+ return currentAverage;
+ }
+ float previousTotal = (float) (currentAverage * ratingCount);
+ float newTotal = previousTotal + newRating;
ratingCount++;
currentAverage = newTotal / ratingCount;
return currentAverage;
diff --git a/src/test/java/edu/bristol/IMDBRatingTest.java b/src/test/java/edu/bristol/IMDBRatingTest.java
index 76a9e9c..7ab0e92 100644
--- a/src/test/java/edu/bristol/IMDBRatingTest.java
+++ b/src/test/java/edu/bristol/IMDBRatingTest.java
@@ -16,5 +16,35 @@ public void testAverageRating()
averageRating = rater.addNewRating(4);
assertTrue(averageRating == 3.0, "Adding 2nd rating: average should be 3.0");
+
+ }
+ @Test
+ public void testAverageRating2()
+ {
+ float averageRating;
+ IMDBRating rater = new IMDBRating();
+
+ averageRating = rater.addNewRating(1);
+ assertTrue(averageRating == 1.0, "Adding 1st rating: average should be 1.0");
+
+ averageRating = rater.addNewRating(2);
+ assertTrue(averageRating == 1.5, "Adding 2nd rating: average should be 1.5");
+
+ }
+ @Test
+ public void testAverageRating3()
+ {
+ float averageRating;
+ IMDBRating rater = new IMDBRating();
+
+ averageRating = rater.addNewRating(2);
+ assertTrue(averageRating == 2.0);
+
+ averageRating = rater.addNewRating(11);
+ assertTrue(averageRating == 2.0);
+
+ averageRating = rater.addNewRating(-1);
+ assertTrue(averageRating == 2.0);
+
}
}
diff --git a/target/classes/edu/bristol/IMDBRating.class b/target/classes/edu/bristol/IMDBRating.class
new file mode 100644
index 0000000..d7ac85a
Binary files /dev/null and b/target/classes/edu/bristol/IMDBRating.class differ
diff --git a/target/test-classes/edu/bristol/IMDBRatingTest.class b/target/test-classes/edu/bristol/IMDBRatingTest.class
new file mode 100644
index 0000000..f495afd
Binary files /dev/null and b/target/test-classes/edu/bristol/IMDBRatingTest.class differ