Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.booleanuk.helpers.ExerciseBase;

import static java.lang.Math.abs;

public class Exercise extends ExerciseBase {
/*
A method is a function, a single piece of logic that can run. In Java, a class is a convenient
Expand Down Expand Up @@ -35,7 +37,7 @@ public String greet(String name) {
Complete this method so that it increases the number given by 1 and returns the result
*/
public int increment(int number) {
return 0;
return number+1;
}

/*
Expand All @@ -48,10 +50,9 @@ public int increment(int number) {
Nathan | Hi, Nathan :)
Edward | Hi, Edward :)
*/
public String happilyGreet() {
return "Not implemented yet";
public String happilyGreet(String s1) {
return "Hi, "+s1+ " :)";
}

/*
3. Construct an array of numbers
Create a method named constructNumberArray that accepts two whole numbers named lower and upper.
Expand All @@ -65,6 +66,23 @@ public String happilyGreet() {
-1, 1 | [-1,0,1]
*/

public int[] constructNumberArray(int num1, int num2) {
if (num1 > num2) {
int num3 = num2;
num2 =num1;
num1 = num3;

}
int diff = abs(num1 - num2) + 1;
int[] numbers = new int[diff];
int j = 0;
for(int i = num1; i<=num2;i++ ){
numbers[j] = i;
j++;
}

return numbers;
}



Expand All @@ -82,6 +100,21 @@ The method must return the same string in upper case with exclamation marks (!)
*/


public String shout(String s1, int num2) {
s1 = s1.toUpperCase();
for (int i =0; i < num2; i++){
s1= s1+"!";
}
return s1;







}



}
Loading