Commit adf8d516 authored by liam.wadsworth's avatar liam.wadsworth

Initial commit

parent 7805f22d
Pipeline #232 failed with stages
public class AssessmentPartOne { public class AssessmentPartOne {
public int biggestOfThree(int num1, int num2, int num3) public int biggestOfThree(int num1, int num2, int num3)
...@@ -7,8 +6,10 @@ public class AssessmentPartOne { ...@@ -7,8 +6,10 @@ 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)
{ //changed the < to > as the test was only True when the 3rd number was the largest
//this happens because num1 can't be identified as the largest number as it is never checked
{
if (num3>num1) if (num3>num1)
{ {
return num3; return num3;
...@@ -18,6 +19,7 @@ public class AssessmentPartOne { ...@@ -18,6 +19,7 @@ public class AssessmentPartOne {
return num1; return num1;
} }
} }
else else
{ {
if (num3>num2) if (num3>num2)
...@@ -26,7 +28,7 @@ public class AssessmentPartOne { ...@@ -26,7 +28,7 @@ public class AssessmentPartOne {
} }
else else
{ {
return num2 return num2; //added semicolon after num2
} }
} }
} }
...@@ -43,8 +45,23 @@ public class AssessmentPartOne { ...@@ -43,8 +45,23 @@ public class AssessmentPartOne {
// You should comment your code explaining what each part does // You should comment your code explaining what each part does
int sumOfSquares = 0; int sumOfSquares = 0;
int sumNum = 0;
//This number will represent an individual number that is between the start and end
if ((end < start)||(end == start - 1)||(start < 0)||(end < 0)||(end == start + 1))
//Checks if any of the numbers are negatives or if the start number is smaller than the end number
{
sumOfSquares = -1;
//Sets sumOfSquares to -1 if any of these issues are found
return sumOfSquares;
}
for (int i = 1; i < (end - start); i++)
//Sets i to 1 and loops for the amount of numbers that are between the start and end numbers
{
sumNum = start + i;
//Adds i to the starting number which allows the loop to get each number that is between start and end
sumOfSquares = sumNum + sumOfSquares;
//Adds this number to the total
}
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