Commit e63ad7ad authored by joel.guest's avatar joel.guest

initial

parent 7805f22d
Pipeline #367 failed with stages
...@@ -7,17 +7,21 @@ public class AssessmentPartOne { ...@@ -7,17 +7,21 @@ public class AssessmentPartOne {
// Debug this method so it passes the unit test. // Debug this method so it passes the unit test.
// Add comments beside any changes you make // Add comments beside any changes you make
if (num1<num2) if (num1>num2)
// LOGICAL ERROR (changed the sign so that num1 is greater then num2)
{ {
if (num3>num1) if (num3>num1)
{ {
return num3; return num3;
//now if num3 is bigger than num1 it means it is the biggest
} }
else else
{ {
return num1; return num1;
//if num3 is not bigger than num1 then num1 is the biggest
} }
} }
//if num1 is not greater than num2 it means num2 or num3 is bigger meaning it moves straight to this else
else else
{ {
if (num3>num2) if (num3>num2)
...@@ -26,13 +30,13 @@ public class AssessmentPartOne { ...@@ -26,13 +30,13 @@ public class AssessmentPartOne {
} }
else else
{ {
return num2 return num2;
// SYNTAX ERROR (semi-colon is added after num2)
} }
} }
} }
public int sumNumbersBetween(int start, int end) public int sumNumbersBetween(int start, int end) {
{
// 02 - Adding Across A Range // 02 - Adding Across A Range
// Complete this method so that it adds together all // Complete this method so that it adds together all
// the integers between start and end, but not including // the integers between start and end, but not including
...@@ -44,8 +48,32 @@ public class AssessmentPartOne { ...@@ -44,8 +48,32 @@ public class AssessmentPartOne {
int sumOfSquares = 0; int sumOfSquares = 0;
//DEFAULT
//if the start value is less than 0 the programme will return -1 as it only deals with positive integers
if (start <0){
return -1;
}
//if the end value is less than 0 the programme will return -1 as it only deals with positive integers
if (end<0){
return -1;
}
//if the start value is less then the end value the programme will return -1
//it does this by making sure start +1 is grater than end-1
if (end-1 <= start+1){
return -1;
}
//if none of the default tests are through it runs an else with the for loop that holds the code that adds the values within the range
else {
// this for loop loops between all the values within the range of start and end excluding the values of start and end themselves
for (int i = start +1; i<=end -1 ; i++) {
//adds all the integers between start and end
sumOfSquares = sumOfSquares + i;
}
}
return sumOfSquares; return sumOfSquares;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment