From 034895e004e822943a6feb20b1750b13f776d9df Mon Sep 17 00:00:00 2001 From: Olga Berezhna Date: Mon, 28 Nov 2016 14:26:59 +0200 Subject: [PATCH 01/12] t1_done --- .../lemon/changerequest/java/introduction/hw2/Task1.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task1.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task1.java index fb8a529..25571c5 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task1.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task1.java @@ -2,6 +2,7 @@ public class Task1 { public static String makeTags(String tag, String text) { - return ""; + + return String.format("%s", "<" + tag + ">" + text + ""); } } From 95607211fd38f6df604d3fdf1c9a12c3bfedaa90 Mon Sep 17 00:00:00 2001 From: Olga Berezhna Date: Mon, 28 Nov 2016 15:02:27 +0200 Subject: [PATCH 02/12] t2_done --- .../changerequest/java/introduction/hw2/Task2.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task2.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task2.java index fd4494e..1203610 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task2.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task2.java @@ -3,6 +3,17 @@ public class Task2 { public static String firstTwo(String s) { - return ""; + + if (s == null) { + return null; + } + + + if (s.length() < 2) { + return s; + } + else { + return s.substring(0, 1); + } } } From 98003138f89feb9364ac44988f940b400736de5b Mon Sep 17 00:00:00 2001 From: Olga Berezhna Date: Mon, 28 Nov 2016 17:35:32 +0200 Subject: [PATCH 03/12] t3_done --- .../java/introduction/hw2/Task3.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task3.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task3.java index 4d2e987..df73f5b 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task3.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task3.java @@ -3,6 +3,20 @@ public class Task3 { public static String comboString(String s1, String s2) { - return ""; + if (s1 == null){ + s1 = String.valueOf(s1); + } + + if (s1.length() > s2.length()) + { + StringBuffer newstring = new StringBuffer(); + newstring.append(s2).append(s1).append(s2); + return newstring.toString(); + } + else { + StringBuffer newstring2 = new StringBuffer(); + newstring2.append(s1).append(s2).append(s1); + return newstring2.toString(); + } } } From 53a062151e6828d2826147617725ff80c87cf7cd Mon Sep 17 00:00:00 2001 From: Olga Berezhna Date: Wed, 30 Nov 2016 14:06:44 +0200 Subject: [PATCH 04/12] t4_done --- .../java/introduction/hw2/Task4.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task4.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task4.java index 35edd98..ff51551 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task4.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task4.java @@ -2,6 +2,24 @@ public class Task4 { public static String charAt(String s, int i) { - return ""; + + if (s == null) { + return null; + } + int len = s.length(); + if (len < 0) { + if (Math.abs(i) >= len) { + while (Math.abs(i) > len) { + i = Math.abs(i) - len; + } + } + return String.valueOf(s.charAt(len - Math.abs(i))); + } + else { + if (i >= len) { + while (i >= len) i-= len; + } + return String.valueOf(s.charAt(i)); + } } } From d2d1f515cd7025c1a83d53b9ffe75f431e4a07f0 Mon Sep 17 00:00:00 2001 From: Olga Berezhna Date: Wed, 30 Nov 2016 14:36:04 +0200 Subject: [PATCH 05/12] t5_done --- .../school/lemon/changerequest/java/introduction/hw2/Task5.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task5.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task5.java index 5e42b95..b806a8f 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task5.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task5.java @@ -2,6 +2,6 @@ public class Task5 { public static boolean commondEnd(int[] a, int[] b) { - return false; + return (a[0]==b[0] || a[a.length - 1]== b[b.length - 1] || a[0]==b[b.length - 1] || b[0]== a[a.length - 1]); } } From 42a708b666fcd28c87268e6e8dc2fb5572bae399 Mon Sep 17 00:00:00 2001 From: Olga Berezhna Date: Wed, 30 Nov 2016 15:11:30 +0200 Subject: [PATCH 06/12] t6_done --- .../changerequest/java/introduction/hw2/Task6.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task6.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task6.java index ee19236..1140540 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task6.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task6.java @@ -1,8 +1,14 @@ package school.lemon.changerequest.java.introduction.hw2; - public class Task6 { public static int[] reverse(int[] arr) { - return null; + if (arr == null) { + return null; + } + int reverseArr[] = new int[arr.length]; + for (int i = arr.length-1; i >= 0; i--) { + reverseArr[arr.length - i - 1] = arr[i]; + } + return reverseArr; } } From a4516605aa4a57929eede062483b3ad613bb1415 Mon Sep 17 00:00:00 2001 From: Olga Berezhna Date: Wed, 30 Nov 2016 19:31:25 +0200 Subject: [PATCH 07/12] t7_done --- .../lemon/changerequest/java/introduction/hw2/Task7.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java index f95de42..9e7ca06 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java @@ -2,6 +2,11 @@ public class Task7 { public static int countEvens(int[] arr) { - return 0; + int evenNum = 0; + for (int anArr : arr) { + if (anArr % 2 == 0) evenNum++; + } + + return evenNum; } } From 19101d1327c83be7c328754cb74827b31e1ba950 Mon Sep 17 00:00:00 2001 From: Olga Berezhna Date: Wed, 30 Nov 2016 20:43:18 +0200 Subject: [PATCH 08/12] t8_done --- .../java/introduction/hw2/Task7.java | 4 +++- .../java/introduction/hw2/Task8.java | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java index 9e7ca06..72b5085 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java @@ -4,7 +4,9 @@ public class Task7 { public static int countEvens(int[] arr) { int evenNum = 0; for (int anArr : arr) { - if (anArr % 2 == 0) evenNum++; + if (anArr % 2 == 0) { + evenNum++; + } } return evenNum; diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task8.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task8.java index 271facb..e693126 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task8.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task8.java @@ -3,6 +3,21 @@ public class Task8 { public static int[] evenOdd(int[] arr) { - return null; + + int sortArr[] = new int[arr.length]; + int j = 0; + for (int anArr : arr) { + if (anArr % 2 == 0) + sortArr[j++] = arr[anArr]; + } + + int n = 0; + for (int newArr: arr) { + if (newArr % 2 != 0) { + sortArr[j + n++] = arr[newArr]; + } + } + + return sortArr; } } From c09e6879781bba001c17c19bb35456966afc38ef Mon Sep 17 00:00:00 2001 From: Olga Berezhna Date: Thu, 1 Dec 2016 18:22:15 +0200 Subject: [PATCH 09/12] t10_done --- .../changerequest/java/introduction/hw2/Task10.java | 13 +++++++++++++ .../changerequest/java/introduction/hw2/Task9.java | 1 + 2 files changed, 14 insertions(+) diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task10.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task10.java index 95ec7eb..e3696ac 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task10.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task10.java @@ -1,7 +1,20 @@ package school.lemon.changerequest.java.introduction.hw2; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + public class Task10 { public static String trim(String text) { + if (text == null) { + return null; + } + String regExp = "(((?<=[\\t]\\s)[a-z,A-Z]+.*[^\\s\\t]+)|([A-Z]).*[^\\t\\s])"; + Pattern pattern = Pattern.compile(regExp); + Matcher matcher = pattern.matcher(text); + if (matcher.find()){ + return matcher.group(); + } return ""; + } } diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task9.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task9.java index 267a59d..b93f123 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task9.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task9.java @@ -2,6 +2,7 @@ public class Task9 { public static String[] extractData(String URL) { + return new String[]{"", "", ""}; } } From 205bcbec1b043d5065cdaa0a3c43a0618a051523 Mon Sep 17 00:00:00 2001 From: Olga Berezhna Date: Sat, 10 Dec 2016 21:58:34 +0200 Subject: [PATCH 10/12] Task 9 done --- .../java/introduction/hw2/Task9.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task9.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task9.java index b93f123..c6166f9 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task9.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task9.java @@ -1,8 +1,27 @@ package school.lemon.changerequest.java.introduction.hw2; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + public class Task9 { public static String[] extractData(String URL) { - return new String[]{"", "", ""}; + if (URL == null) { + + return new String[]{"", "", ""}; + } + Pattern pattern = Pattern.compile("(?:([a-z]+):\\/\\/)?([\\da-z._-]+)(?::(\\d+)?)?.*"); + //"(?:(\w+):\/\/)?([\d\w._-]+)(?::(\d+)?)?.*" + Matcher matcher = pattern.matcher(URL); + + + if (matcher.matches()) { + String scheme = matcher.group(1); + String host = matcher.group(2); + String port = matcher.group(3); + return new String[] {scheme != null ? scheme : "", host != null ? host : "", port != null ? port : ""}; + + } + return new String[] {"", "", ""}; } } From 87c44a2107e6f0126bc07a82b0216a7455dfa0e7 Mon Sep 17 00:00:00 2001 From: Olga Berezhna Date: Sat, 10 Dec 2016 23:24:40 +0200 Subject: [PATCH 11/12] Task 1, 3, 7, 8 fixed --- .../lemon/changerequest/java/introduction/hw2/Task1.java | 4 +++- .../lemon/changerequest/java/introduction/hw2/Task3.java | 4 ++-- .../lemon/changerequest/java/introduction/hw2/Task7.java | 2 ++ .../lemon/changerequest/java/introduction/hw2/Task8.java | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task1.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task1.java index 25571c5..3edef45 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task1.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task1.java @@ -2,7 +2,9 @@ public class Task1 { public static String makeTags(String tag, String text) { + StringBuilder tagText = new StringBuilder(); + tagText.append("<").append(tag).append(">").append(text).append(""); + return tagText.toString(); - return String.format("%s", "<" + tag + ">" + text + ""); } } diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task3.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task3.java index df73f5b..dabcc7c 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task3.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task3.java @@ -9,12 +9,12 @@ public static String comboString(String s1, String s2) { if (s1.length() > s2.length()) { - StringBuffer newstring = new StringBuffer(); + StringBuilder newstring = new StringBuilder(); newstring.append(s2).append(s1).append(s2); return newstring.toString(); } else { - StringBuffer newstring2 = new StringBuffer(); + StringBuilder newstring2 = new StringBuilder(); newstring2.append(s1).append(s2).append(s1); return newstring2.toString(); } diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java index 72b5085..333ef10 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java @@ -2,6 +2,8 @@ public class Task7 { public static int countEvens(int[] arr) { + if (arr == null) return 0; + int evenNum = 0; for (int anArr : arr) { if (anArr % 2 == 0) { diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task8.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task8.java index e693126..662651f 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task8.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task8.java @@ -3,6 +3,7 @@ public class Task8 { public static int[] evenOdd(int[] arr) { + if (arr == null) return null; int sortArr[] = new int[arr.length]; int j = 0; From 4b8d2327d0542961674015cc40f56dc83b622494 Mon Sep 17 00:00:00 2001 From: Olga Berezhna Date: Mon, 12 Dec 2016 16:08:30 +0200 Subject: [PATCH 12/12] Task 2 fixed --- .../school/lemon/changerequest/java/introduction/hw2/Task2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task2.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task2.java index 1203610..0d8caa0 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task2.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task2.java @@ -13,7 +13,7 @@ public static String firstTwo(String s) { return s; } else { - return s.substring(0, 1); + return s.substring(0, 2); } } }