Click here to download the IntelliJ project for this exercise. Alternatively, you can find all the exercices on this git repository
This exercise is already available in your IntelliJ as a project.
What you need to do is described in the comments at the top of the file in src/main/java/
.
package basics; public class IntroductionExercises { public static int variable = 0; public static int[] squares; /* * Function that bound variable to value */ public static void attribute(int value){ } /* * Function that return the addition of the two parameters */ public static int add(int a, int b){ return 0; } /* * return true is a and b are equal */ public static boolean equalsIntegers(int a, int b){ return false; } /* * Function that return the max between a and b in one line * You must use a ternary operation */ public static int max(int a, int b){ return 0; } /* * Function that return the middle value. * If a > b > c, the function must return b. * If two value are equals, return -1. */ public static int middleValue(int a, int b, int c){ return 0; } /* * This function must return : * "Good morning, sir!" if str is "Morning" * "Good evening, sir!" if str is "Evening" * "Hello, sir!" otherwise * Use a switch case statement * Your implementation must be case sensitive * And you should not use if/else! */ public static String greetings(String str){ return ""; } /* * This function must return a new array of length 3 * The first element of this new array is the last element of a * The second element is the first element of a * The last element is the middle element of a */ public static int[] lastFirstMiddle(int[] a){ return null; } /* * This function must return the sum of the elements of array using a for loop */ public static int sum(int[] array){ return 0; } /* * return the maximum element of array using a while loop */ public static int maxArray(int[] array){ return 0; } /** * Assign to the variable square, the square of the * parameters. * * Let assume that the program is invoked with the following * line: * java IntroductionExercises 0 3 4 5 * * The arguments of the program are 0, 3, 4 and 5. * After the execution of the main, the variable squares * should be: * squares = [0, 9, 16, 25] * * If an exception occurs when converting an argument to * an integer, put 0 at the corresponding index. For example * * java IntroductionExercise 0 3.1 4 5 * * would yield * * squares = [0, 0, 16, 25] * * because 3.1 can not be converted to an integer * */ public static void main(String... args){ } }
- Instruction provided at the top of the source file on IntelliJ.
- Debug using small and easy unit tests provided in junit tests, it can also help to clarify the instructions.