Commit c37dfd89 authored by ash.brett's avatar ash.brett

Update AssessmentPartOne.java

parent 9e0d8cbf
public class AssessmentPartOne {
public int biggestOfThree(int num1, int num2, int num3)
{
// 01 - A Gentle Start
// Debug this method so it passes the unit test.
// Add comments beside any changes you make
//Changed this From a less than to a greater than
if (num1>num2)
{
if (num3>num1)
{
return num3;
}
else
{
return num1;
}
}
else
{
if (num3>num2)
{
return num3;
}
else
{
return num2;//Added A semiColone here
}
}
}
public int sumNumbersBetween(int start, int end)
{
// 02 - Adding Across A Range
// Complete this method so that it adds together all
// the integers between start and end, but not including
// start or end
// This method should only deal with 0 and positive integers
// This method should return -1 if it cannot calculate the result
// You should comment your code explaining what each part does
//Setting up the Primitive int data type of sumOfNumbers and setting it's value to 0
int sumOfNumbers = 0;
//This section of the program states that if start is greater than the end value it will set the sumONumbers to be equal to -1 as specified by the brief it then returns this value.
//If this is not the case it will continue onto the next elseif section
if(start > end) {
sumOfNumbers = -1;
return sumOfNumbers;
}
//This section of the program states that if start is less than 0 or if end is less than or equal to 0 it will set the sumOfNumbers to be equal to -1 and it will then return this value
//If this is not the case it will continue onto the next elseif section
else if(start < 0 || end <= 0) {
sumOfNumbers = -1;
return sumOfNumbers;
}
//This section of the program states that if start plus 1 is equal to end it will set sumOfNumbers to equal -1.
//If this is not the case it will continue onto the next section of the program
else if(start + 1 == end) {
sumOfNumbers = -1;
return sumOfNumbers;
}
//This section of the program states while start is less than end-1 it will increment the start value. It will then add start to the sumOfNumbers, It then returns this value.
//It continues to run through this section of code until the start becomes equal to end-1
while(start < end-1) {
++start;
sumOfNumbers+=start;
}
return sumOfNumbers;
}
}
public class AssessmentPartOne {
public int biggestOfThree(int num1, int num2, int num3)
{
// 01 - A Gentle Start
// Debug this method so it passes the unit test.
// Add comments beside any changes you make
//Changed this From a less than to a greater than
if (num1>num2)
{
if (num3>num1)
{
return num3;
}
else
{
return num1;
}
}
else
{
if (num3>num2)
{
return num3;
}
else
{
return num2;//Added A semicolon here
}
}
}
public int sumNumbersBetween(int start, int end)
{
// 02 - Adding Across A Range
// Complete this method so that it adds together all
// the integers between start and end, but not including
// start or end
// This method should only deal with 0 and positive integers
// This method should return -1 if it cannot calculate the result
// You should comment your code explaining what each part does
//Setting up the Primitive int data type of sumOfNumbers and setting it's value to 0
int sumOfNumbers = 0;
//This section of the program states that if start is greater than the end value it will set the sumONumbers to be equal to -1 as specified by the brief it then returns this value.
//If this is not the case it will continue onto the next elseif section
if(start > end) {
sumOfNumbers = -1;
return sumOfNumbers;
}
//This section of the program states that if start is less than 0 or if end is less than or equal to 0 it will set the sumOfNumbers to be equal to -1 and it will then return this value
//If this is not the case it will continue onto the next elseif section
else if(start < 0 || end <= 0) {
sumOfNumbers = -1;
return sumOfNumbers;
}
//This section of the program states that if start plus 1 is equal to end it will set sumOfNumbers to equal -1.
//If this is not the case it will continue onto the next section of the program
else if(start + 1 == end) {
sumOfNumbers = -1;
return sumOfNumbers;
}
//This section of the program states while start is less than end-1 it will increment the start value. It will then add start to the sumOfNumbers, It then returns this value.
//It continues to run through this section of code until the start becomes equal to the end value -1
while(start < end-1) {
++start;
sumOfNumbers+=start;
}
return sumOfNumbers;
}
}
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