From e8242ac50753385448e98fb7cbd630711c1b58f0 Mon Sep 17 00:00:00 2001 From: "Ilnytskiy,Serhii" Date: Fri, 9 Dec 2022 23:45:24 +0200 Subject: [PATCH 1/3] OT-1: Completed introduction exercise --- .../java/com/bobocode/intro/ExerciseIntroduction.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/0-0-intro/src/main/java/com/bobocode/intro/ExerciseIntroduction.java b/0-0-intro/src/main/java/com/bobocode/intro/ExerciseIntroduction.java index 35d925636..d3b3e15d1 100644 --- a/0-0-intro/src/main/java/com/bobocode/intro/ExerciseIntroduction.java +++ b/0-0-intro/src/main/java/com/bobocode/intro/ExerciseIntroduction.java @@ -1,6 +1,7 @@ package com.bobocode.intro; -import com.bobocode.util.ExerciseNotCompletedException; +import java.nio.charset.StandardCharsets; +import java.util.Base64; /** * Welcome! This is an introduction exercise that will show you a simple example of Bobocode exercises. @@ -16,6 +17,8 @@ * @author Taras Boychuk */ public class ExerciseIntroduction { + + private static final String VARY_IMPORTANT_MESSAGE = "The key to efficient learning is practice!"; /** * This method returns a very important message. If understood well, it can save you years of inefficient learning, * and unlock your potential! @@ -23,8 +26,7 @@ public class ExerciseIntroduction { * @return "The key to efficient learning is practice!" */ public String getWelcomeMessage() { - // todo: implement a method and return a message according to javadoc - throw new ExerciseNotCompletedException(); + return VARY_IMPORTANT_MESSAGE; } /** @@ -39,7 +41,6 @@ public String getWelcomeMessage() { * @return encoded message */ public String encodeMessage(String message) { - // todo: switch to branch "completed" in order to see how it should be implemented - throw new ExerciseNotCompletedException(); + return Base64.getEncoder().encodeToString(message.getBytes(StandardCharsets.UTF_8)); } } From bc8cc311aa5e4bb49b8d50e3922cf4c985ac5978 Mon Sep 17 00:00:00 2001 From: "Ilnytskiy,Serhii" Date: Fri, 9 Dec 2022 23:54:47 +0200 Subject: [PATCH 2/3] OT-1: Find max java vs js --- .../main/java/com/bobocode/intro/FindMax.java | 21 +++++++++++++++++++ .../main/java/com/bobocode/intro/findMax.js | 14 +++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 0-0-intro/src/main/java/com/bobocode/intro/FindMax.java create mode 100644 0-0-intro/src/main/java/com/bobocode/intro/findMax.js diff --git a/0-0-intro/src/main/java/com/bobocode/intro/FindMax.java b/0-0-intro/src/main/java/com/bobocode/intro/FindMax.java new file mode 100644 index 000000000..995da9765 --- /dev/null +++ b/0-0-intro/src/main/java/com/bobocode/intro/FindMax.java @@ -0,0 +1,21 @@ +package com.bobocode.intro; + +public class FindMax { + public static void main(String[] args) { + System.out.println(findMax(new int[]{1, 2, 23, 24, 98, 4})); + System.out.println(findMax(new int[]{})); + } + + public static int findMax(int[] input) { + if (0 == input.length) { + throw new IllegalArgumentException("Array is empty"); + } + int max = input[0]; + for (int i = 1; i < input.length; i++) { + if (input[i] > max) { + max = input[i]; + } + } + return max; + } +} diff --git a/0-0-intro/src/main/java/com/bobocode/intro/findMax.js b/0-0-intro/src/main/java/com/bobocode/intro/findMax.js new file mode 100644 index 000000000..1821dfe47 --- /dev/null +++ b/0-0-intro/src/main/java/com/bobocode/intro/findMax.js @@ -0,0 +1,14 @@ +function findMax(array) { + let max; + if (array) { + max = array[0]; + for (let i = 0; i < array.length; i++) { + if (array[i] > max) { + max = array[i]; + } + } + } + return max; +} + +console.log(findMax([1, 2, 34, 23, 22])); From e002596c0db0f568bdd0fca93852dc7200ef6cc3 Mon Sep 17 00:00:00 2001 From: "Ilnytskiy,Serhii" Date: Sat, 10 Dec 2022 00:19:15 +0200 Subject: [PATCH 3/3] HW-1: Created sample of StackOverflowError and OutOfMemoryError --- .../basics/StackOverflowOutOfMemory.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 1-0-java-basics/1-3-0-hello-generics/src/main/java/com/bobocode/basics/StackOverflowOutOfMemory.java diff --git a/1-0-java-basics/1-3-0-hello-generics/src/main/java/com/bobocode/basics/StackOverflowOutOfMemory.java b/1-0-java-basics/1-3-0-hello-generics/src/main/java/com/bobocode/basics/StackOverflowOutOfMemory.java new file mode 100644 index 000000000..69979307f --- /dev/null +++ b/1-0-java-basics/1-3-0-hello-generics/src/main/java/com/bobocode/basics/StackOverflowOutOfMemory.java @@ -0,0 +1,25 @@ +package com.bobocode.basics; + +public class StackOverflowOutOfMemory { + + public static void main(String[] args) { + try { + throwStackOverFlow(); + } catch (StackOverflowError er) { + System.out.println("StackOverflowError caught"); + } + try { + throwOutOfMemory(); + } catch (OutOfMemoryError er) { + System.out.println("OutOfMemoryError caught"); + } + } + + private static void throwStackOverFlow() { + throwStackOverFlow(); + } + + private static void throwOutOfMemory() { + byte[] bytes = new byte[Integer.MAX_VALUE]; + } +}