From dafdc2dc7bfbd834a529541a8f852a5528cda450 Mon Sep 17 00:00:00 2001 From: HJavid010 Date: Sat, 16 Mar 2024 22:06:41 +0330 Subject: [PATCH 01/13] Created project in answers folder --- .../Functions-Introduction/.gitignore | 38 +++++++++++++++++++ .../Functions-Introduction/.idea/.gitignore | 3 ++ .../.idea/encodings.xml | 7 ++++ .../Functions-Introduction/.idea/misc.xml | 14 +++++++ .../Functions-Introduction/.idea/vcs.xml | 6 +++ .../Functions-Introduction/pom.xml | 17 +++++++++ 6 files changed, 85 insertions(+) create mode 100644 Answers/40230112037/Functions-Introduction/.gitignore create mode 100644 Answers/40230112037/Functions-Introduction/.idea/.gitignore create mode 100644 Answers/40230112037/Functions-Introduction/.idea/encodings.xml create mode 100644 Answers/40230112037/Functions-Introduction/.idea/misc.xml create mode 100644 Answers/40230112037/Functions-Introduction/.idea/vcs.xml create mode 100644 Answers/40230112037/Functions-Introduction/pom.xml diff --git a/Answers/40230112037/Functions-Introduction/.gitignore b/Answers/40230112037/Functions-Introduction/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/Answers/40230112037/Functions-Introduction/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Answers/40230112037/Functions-Introduction/.idea/.gitignore b/Answers/40230112037/Functions-Introduction/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Answers/40230112037/Functions-Introduction/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Answers/40230112037/Functions-Introduction/.idea/encodings.xml b/Answers/40230112037/Functions-Introduction/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/Answers/40230112037/Functions-Introduction/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Answers/40230112037/Functions-Introduction/.idea/misc.xml b/Answers/40230112037/Functions-Introduction/.idea/misc.xml new file mode 100644 index 0000000..82dbec8 --- /dev/null +++ b/Answers/40230112037/Functions-Introduction/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112037/Functions-Introduction/.idea/vcs.xml b/Answers/40230112037/Functions-Introduction/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/Answers/40230112037/Functions-Introduction/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Answers/40230112037/Functions-Introduction/pom.xml b/Answers/40230112037/Functions-Introduction/pom.xml new file mode 100644 index 0000000..d01cd91 --- /dev/null +++ b/Answers/40230112037/Functions-Introduction/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + Functions-Introduction + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + \ No newline at end of file From a8dd03f00e5b2f00e0cd6718b3292c49e2f82853 Mon Sep 17 00:00:00 2001 From: HJavid010 Date: Mon, 18 Mar 2024 19:19:37 +0330 Subject: [PATCH 02/13] Created Main file --- .../Functions-Introduction/src/main/java/Main.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Answers/40230112037/Functions-Introduction/src/main/java/Main.java diff --git a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java new file mode 100644 index 0000000..bfe22fd --- /dev/null +++ b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java @@ -0,0 +1,7 @@ +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + + } +} From afce9c3aa6e56803ff13294d36290385742471a9 Mon Sep 17 00:00:00 2001 From: HJavid010 Date: Fri, 22 Mar 2024 23:12:55 +0330 Subject: [PATCH 03/13] Added normalizeName function --- .../Functions-Introduction/src/main/java/Main.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java index bfe22fd..4a41229 100644 --- a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java +++ b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java @@ -4,4 +4,8 @@ public class Main { public static void main(String[] args) { } + + public static String normalizeName(String name) { + return name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase(); + } } From 0e7a90f65bef2c58f6459f50f916a60b18f7259f Mon Sep 17 00:00:00 2001 From: HJavid010 Date: Fri, 22 Mar 2024 23:13:26 +0330 Subject: [PATCH 04/13] Added fullName function --- .../Functions-Introduction/src/main/java/Main.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java index 4a41229..be7cd7e 100644 --- a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java +++ b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java @@ -8,4 +8,16 @@ public static void main(String[] args) { public static String normalizeName(String name) { return name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase(); } + + public static String fullName(String firstName, String lastName) { + if (firstName.isBlank()) { + throw new Error("firstName is Empty!"); + } + if (lastName.isBlank()) { + throw new Error("lastName is Empty!"); + } + firstName = normalizeName(firstName); + lastName = normalizeName(lastName); + return firstName + " " + lastName; + } } From fec40b21aec5a20e589b018636c3c383496ebd4f Mon Sep 17 00:00:00 2001 From: HJavid010 Date: Fri, 22 Mar 2024 23:14:07 +0330 Subject: [PATCH 05/13] Added phoneNumber function --- .../src/main/java/Main.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java index be7cd7e..a9239e5 100644 --- a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java +++ b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java @@ -20,4 +20,28 @@ public static String fullName(String firstName, String lastName) { lastName = normalizeName(lastName); return firstName + " " + lastName; } + + public static String phoneNumber(String phone) { + switch (phone.length()) { + case 10: + if (phone.charAt(0) != '9') { + throw new Error("invalid phone number! (enter phone number like 09xxxxxxxxx or 9xxxxxxxxx)"); + } + phone = "0" + phone; + break; + case 11: + if (phone.charAt(0) != '0' || phone.charAt(1) != '9') { + throw new Error("invalid phone number! (enter phone number like 09xxxxxxxxx or 9xxxxxxxxx)"); + } + break; + default: + throw new Error("invalid phone number! (phone number length should be 10 or 11)"); + } + for (char i : phone.toCharArray()) { + if (i < '0' || i > '9') { + throw new Error("invalid phone number! (phone number should only contains numbers)"); + } + } + return phone; + } } From b9c175ac2b278c4feb1450a43228eccea0f16e1c Mon Sep 17 00:00:00 2001 From: HJavid010 Date: Fri, 22 Mar 2024 23:14:35 +0330 Subject: [PATCH 06/13] Added userId function --- .../Functions-Introduction/src/main/java/Main.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java index a9239e5..87ae45a 100644 --- a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java +++ b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java @@ -44,4 +44,16 @@ public static String phoneNumber(String phone) { } return phone; } + + public static String userId(String id) { + if (id.length() < 4 || id.length() > 13) { + throw new Error("id is not valid! (id length should be between 4 and 13)"); + } + for (char i : id.toCharArray()) { + if (i < '0' || i > '9') { + throw new Error("id is not valid! (id should only contains numbers)"); + } + } + return id; + } } From b890e915148ad3a2e07e6d12a6d6515949137a43 Mon Sep 17 00:00:00 2001 From: HJavid010 Date: Fri, 22 Mar 2024 23:15:08 +0330 Subject: [PATCH 07/13] Added arrayToString function --- .../Functions-Introduction/src/main/java/Main.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java index 87ae45a..b03fcc7 100644 --- a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java +++ b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java @@ -56,4 +56,15 @@ public static String userId(String id) { } return id; } + + public static String arrayToString(String[] array) { + StringBuilder arrayString = new StringBuilder(); + for (int i = 0; i < array.length; i++) { + arrayString.append(i + 1); + arrayString.append(". "); + arrayString.append(array[i]); + if (i != array.length - 1) arrayString.append("\n"); + } + return arrayString.toString(); + } } From f111858da73d028eaeb31a47053d817e36971021 Mon Sep 17 00:00:00 2001 From: HJavid010 Date: Fri, 22 Mar 2024 23:18:16 +0330 Subject: [PATCH 08/13] Added getInterests function and Arrays library --- .../src/main/java/Main.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java index b03fcc7..1b49e61 100644 --- a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java +++ b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java @@ -1,3 +1,4 @@ +import java.util.Arrays; import java.util.Scanner; public class Main { @@ -67,4 +68,20 @@ public static String arrayToString(String[] array) { } return arrayString.toString(); } + + public static String[] getInterests(int number) { + if (number < 1) { + throw new Error("Unexpected error!"); + } + String[] interests = new String[number]; + Scanner scanner = new Scanner(System.in); + int i; + for (i = 0; i < 10; i++) { + String nextLine = scanner.nextLine(); + if (nextLine.isBlank()) break; + interests[i] = nextLine; + } + scanner.close(); + return Arrays.copyOf(interests, i); + } } From 7f2e59fbb12e6a3facdd93b4faa87340ac51f6cd Mon Sep 17 00:00:00 2001 From: HJavid010 Date: Fri, 22 Mar 2024 23:18:54 +0330 Subject: [PATCH 09/13] Added informationEncoder function --- .../src/main/java/Main.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java index 1b49e61..60a4429 100644 --- a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java +++ b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java @@ -84,4 +84,21 @@ public static String[] getInterests(int number) { scanner.close(); return Arrays.copyOf(interests, i); } + + public static String informationEncoder(String information, int shift) { + char[] encodedInformation = new char[information.length()]; + char[] informationChars = information.toCharArray(); + for (int i = 0; i < informationChars.length; i++) { + if (informationChars[i] >= 'a' && informationChars[i] <= 'z') { + encodedInformation[i] = (char) (((informationChars[i] + shift - 'a') + 26) % 26 + 'a'); + } else if (informationChars[i] >= 'A' && informationChars[i] <= 'Z') { + encodedInformation[i] = (char) (((informationChars[i] + shift - 'A') + 26) % 26 + 'A'); + } else if (informationChars[i] >= '0' && informationChars[i] <= '9') { + encodedInformation[i] = (char) (((informationChars[i] + shift - '0') + 10) % 10 + '0'); + } else { + encodedInformation[i] = informationChars[i]; + } + } + return new String(encodedInformation); + } } From 223b49e870249e0d1f6a3f52850226f59c9f46e5 Mon Sep 17 00:00:00 2001 From: HJavid010 Date: Fri, 22 Mar 2024 23:19:18 +0330 Subject: [PATCH 10/13] Added informationDecoder function --- .../Functions-Introduction/src/main/java/Main.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java index 60a4429..396782c 100644 --- a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java +++ b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java @@ -101,4 +101,8 @@ public static String informationEncoder(String information, int shift) { } return new String(encodedInformation); } + + public static String informationDecoder(String information, int shift) { + return informationEncoder(information, -shift); + } } From 9df514775f664d3733794aa28c7e64aa7d6dd34f Mon Sep 17 00:00:00 2001 From: HJavid010 Date: Fri, 22 Mar 2024 23:19:40 +0330 Subject: [PATCH 11/13] Added userFullInformation function --- .../Functions-Introduction/src/main/java/Main.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java index 396782c..c31d602 100644 --- a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java +++ b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java @@ -105,4 +105,9 @@ public static String informationEncoder(String information, int shift) { public static String informationDecoder(String information, int shift) { return informationEncoder(information, -shift); } + + public static String userFullInformation(String fullname, String phonenumber, String userid, String[] interests) { + String intererestsString = (interests.length != 0) ? " Here are some of my interests:\n" + arrayToString(interests) : ""; + return "Hello! My name is " + fullname + ". My ID is " + userid + "." + intererestsString + "\n\nYou can reach me via my phone number " + phonenumber + "."; + } } From 1e3d0fd5172c266f16bda2e859a51db9a2899bc1 Mon Sep 17 00:00:00 2001 From: HJavid010 Date: Fri, 22 Mar 2024 23:21:43 +0330 Subject: [PATCH 12/13] completed main function for resume maker(to input data from user and export resume) --- .../src/main/java/Main.java | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java index c31d602..99e6722 100644 --- a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java +++ b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java @@ -3,7 +3,63 @@ public class Main { public static void main(String[] args) { - + Scanner scanner = new Scanner(System.in); + boolean done = false; + String[] interests = new String[0]; + String firstname, lastname, fullname = "", id = "", phone = ""; + boolean fullNameDone, idDone, phoneDone, interestsDone; + fullNameDone = idDone = phoneDone = interestsDone = false; + while (!done) { + try { + if (!fullNameDone) { + System.out.print("First Name: "); + firstname = scanner.nextLine(); + System.out.print("Last Name: "); + lastname = scanner.nextLine(); + fullname = fullName(firstname, lastname); + fullNameDone = true; + } + if (!phoneDone) { + System.out.print("Phone number: "); + phone = phoneNumber(scanner.nextLine()); + phoneDone = true; + } + if (!idDone) { + System.out.print("User ID: "); + id = userId(scanner.nextLine()); + idDone = true; + } + if (!interestsDone) { + System.out.println("Interests: (Enter an empty line to stop)"); + interests = getInterests(10); + interestsDone = true; + } + done = true; + } catch (Error error) { + System.out.println(error.getMessage()); + } catch (Exception exception) { + System.out.println("Wrong Input!"); + } + } + done = false; + while (!done) { + try { + System.out.print("Do you want to get the output encoded? [Y/n] "); + String input = scanner.nextLine(); + if (input.isBlank() || input.startsWith("y") || input.startsWith("Y")) { + System.out.print("Enter shift value: "); + int shift = scanner.nextInt(); + System.out.println(informationEncoder(userFullInformation(fullname, phone, id, interests), shift)); + done = true; + } else if (input.startsWith("n") || input.startsWith("N")) { + System.out.println(userFullInformation(fullname, phone, id, interests)); + done = true; + } + } catch (Exception exception) { + System.out.println("Unexpected error happened!"); + } + } + scanner.close(); } public static String normalizeName(String name) { From 4897440ef5ea8fe91ad41a4672f394e8d1a30cf0 Mon Sep 17 00:00:00 2001 From: HJavid010 Date: Fri, 22 Mar 2024 23:31:42 +0330 Subject: [PATCH 13/13] removed a scanner.close that caused problem for input --- .../40230112037/Functions-Introduction/src/main/java/Main.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java index 99e6722..418ee78 100644 --- a/Answers/40230112037/Functions-Introduction/src/main/java/Main.java +++ b/Answers/40230112037/Functions-Introduction/src/main/java/Main.java @@ -137,7 +137,6 @@ public static String[] getInterests(int number) { if (nextLine.isBlank()) break; interests[i] = nextLine; } - scanner.close(); return Arrays.copyOf(interests, i); }