From c5c323f7bd4913464f65c57f2f99ab72d6ee7cb5 Mon Sep 17 00:00:00 2001 From: Hossein Date: Mon, 18 Mar 2024 17:38:59 +0330 Subject: [PATCH 01/14] initial the project --- Answers/ResumeMaker/.gitignore | 29 +++++++++++++++++++++++++++ Answers/ResumeMaker/.idea/.gitignore | 3 +++ Answers/ResumeMaker/.idea/misc.xml | 6 ++++++ Answers/ResumeMaker/.idea/modules.xml | 8 ++++++++ Answers/ResumeMaker/.idea/vcs.xml | 6 ++++++ Answers/ResumeMaker/40230112123.iml | 11 ++++++++++ 6 files changed, 63 insertions(+) create mode 100644 Answers/ResumeMaker/.gitignore create mode 100644 Answers/ResumeMaker/.idea/.gitignore create mode 100644 Answers/ResumeMaker/.idea/misc.xml create mode 100644 Answers/ResumeMaker/.idea/modules.xml create mode 100644 Answers/ResumeMaker/.idea/vcs.xml create mode 100644 Answers/ResumeMaker/40230112123.iml diff --git a/Answers/ResumeMaker/.gitignore b/Answers/ResumeMaker/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Answers/ResumeMaker/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Answers/ResumeMaker/.idea/.gitignore b/Answers/ResumeMaker/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Answers/ResumeMaker/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Answers/ResumeMaker/.idea/misc.xml b/Answers/ResumeMaker/.idea/misc.xml new file mode 100644 index 0000000..6f29fee --- /dev/null +++ b/Answers/ResumeMaker/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Answers/ResumeMaker/.idea/modules.xml b/Answers/ResumeMaker/.idea/modules.xml new file mode 100644 index 0000000..7049c5f --- /dev/null +++ b/Answers/ResumeMaker/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Answers/ResumeMaker/.idea/vcs.xml b/Answers/ResumeMaker/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/Answers/ResumeMaker/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Answers/ResumeMaker/40230112123.iml b/Answers/ResumeMaker/40230112123.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Answers/ResumeMaker/40230112123.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From c7f1cabdf77c5256bed207f6f3494044ab77b8c8 Mon Sep 17 00:00:00 2001 From: Hossein Date: Mon, 18 Mar 2024 17:46:03 +0330 Subject: [PATCH 02/14] add fullname function --- Answers/ResumeMaker/src/ResumeMaker.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Answers/ResumeMaker/src/ResumeMaker.java diff --git a/Answers/ResumeMaker/src/ResumeMaker.java b/Answers/ResumeMaker/src/ResumeMaker.java new file mode 100644 index 0000000..2efbbae --- /dev/null +++ b/Answers/ResumeMaker/src/ResumeMaker.java @@ -0,0 +1,23 @@ +public class ResumeMaker +{ + public static void main(String[] args) + { + + } + + public static String fullName(String firstName, String lastName) + { + firstName = firstName.toLowerCase(); + lastName = lastName.toLowerCase(); + + int firstChar = firstName.charAt(0) - 32; + firstName = firstName.substring(1); + firstName = ((char) firstChar) + firstName; + + firstChar = lastName.charAt(0) - 32; + lastName = lastName.substring(1); + lastName = ((char) firstChar) + lastName; + + return (firstName + " " + lastName); + } +} \ No newline at end of file From 57c1ae93e2b1fcc7a35b9eacf422a27cdad23b5f Mon Sep 17 00:00:00 2001 From: Hossein Date: Mon, 18 Mar 2024 17:49:48 +0330 Subject: [PATCH 03/14] initial the project --- .../{ResumeMaker => 40230112123}/.gitignore | 0 .../.idea/.gitignore | 0 .../.idea/misc.xml | 0 .../.idea/modules.xml | 0 .../.idea/vcs.xml | 0 Answers/40230112123/src/ResumeMaker.java | 23 +++++++++++++++++++ Answers/ResumeMaker/40230112123.iml | 11 --------- 7 files changed, 23 insertions(+), 11 deletions(-) rename Answers/{ResumeMaker => 40230112123}/.gitignore (100%) rename Answers/{ResumeMaker => 40230112123}/.idea/.gitignore (100%) rename Answers/{ResumeMaker => 40230112123}/.idea/misc.xml (100%) rename Answers/{ResumeMaker => 40230112123}/.idea/modules.xml (100%) rename Answers/{ResumeMaker => 40230112123}/.idea/vcs.xml (100%) create mode 100644 Answers/40230112123/src/ResumeMaker.java delete mode 100644 Answers/ResumeMaker/40230112123.iml diff --git a/Answers/ResumeMaker/.gitignore b/Answers/40230112123/.gitignore similarity index 100% rename from Answers/ResumeMaker/.gitignore rename to Answers/40230112123/.gitignore diff --git a/Answers/ResumeMaker/.idea/.gitignore b/Answers/40230112123/.idea/.gitignore similarity index 100% rename from Answers/ResumeMaker/.idea/.gitignore rename to Answers/40230112123/.idea/.gitignore diff --git a/Answers/ResumeMaker/.idea/misc.xml b/Answers/40230112123/.idea/misc.xml similarity index 100% rename from Answers/ResumeMaker/.idea/misc.xml rename to Answers/40230112123/.idea/misc.xml diff --git a/Answers/ResumeMaker/.idea/modules.xml b/Answers/40230112123/.idea/modules.xml similarity index 100% rename from Answers/ResumeMaker/.idea/modules.xml rename to Answers/40230112123/.idea/modules.xml diff --git a/Answers/ResumeMaker/.idea/vcs.xml b/Answers/40230112123/.idea/vcs.xml similarity index 100% rename from Answers/ResumeMaker/.idea/vcs.xml rename to Answers/40230112123/.idea/vcs.xml diff --git a/Answers/40230112123/src/ResumeMaker.java b/Answers/40230112123/src/ResumeMaker.java new file mode 100644 index 0000000..2efbbae --- /dev/null +++ b/Answers/40230112123/src/ResumeMaker.java @@ -0,0 +1,23 @@ +public class ResumeMaker +{ + public static void main(String[] args) + { + + } + + public static String fullName(String firstName, String lastName) + { + firstName = firstName.toLowerCase(); + lastName = lastName.toLowerCase(); + + int firstChar = firstName.charAt(0) - 32; + firstName = firstName.substring(1); + firstName = ((char) firstChar) + firstName; + + firstChar = lastName.charAt(0) - 32; + lastName = lastName.substring(1); + lastName = ((char) firstChar) + lastName; + + return (firstName + " " + lastName); + } +} \ No newline at end of file diff --git a/Answers/ResumeMaker/40230112123.iml b/Answers/ResumeMaker/40230112123.iml deleted file mode 100644 index c90834f..0000000 --- a/Answers/ResumeMaker/40230112123.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file From ac21051782070afcd1cdd4cb2473f38ea3933e63 Mon Sep 17 00:00:00 2001 From: Hossein Date: Mon, 18 Mar 2024 17:51:01 +0330 Subject: [PATCH 04/14] add fullName method --- Answers/ResumeMaker/src/ResumeMaker.java | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 Answers/ResumeMaker/src/ResumeMaker.java diff --git a/Answers/ResumeMaker/src/ResumeMaker.java b/Answers/ResumeMaker/src/ResumeMaker.java deleted file mode 100644 index 2efbbae..0000000 --- a/Answers/ResumeMaker/src/ResumeMaker.java +++ /dev/null @@ -1,23 +0,0 @@ -public class ResumeMaker -{ - public static void main(String[] args) - { - - } - - public static String fullName(String firstName, String lastName) - { - firstName = firstName.toLowerCase(); - lastName = lastName.toLowerCase(); - - int firstChar = firstName.charAt(0) - 32; - firstName = firstName.substring(1); - firstName = ((char) firstChar) + firstName; - - firstChar = lastName.charAt(0) - 32; - lastName = lastName.substring(1); - lastName = ((char) firstChar) + lastName; - - return (firstName + " " + lastName); - } -} \ No newline at end of file From e0fd7ca8892f32cf6967614a7652b08ed1c4f694 Mon Sep 17 00:00:00 2001 From: Hossein Date: Mon, 18 Mar 2024 20:39:21 +0330 Subject: [PATCH 05/14] add phoneNumber method --- Answers/40230112123/src/ResumeMaker.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Answers/40230112123/src/ResumeMaker.java b/Answers/40230112123/src/ResumeMaker.java index 2efbbae..d9dc3e0 100644 --- a/Answers/40230112123/src/ResumeMaker.java +++ b/Answers/40230112123/src/ResumeMaker.java @@ -20,4 +20,12 @@ public static String fullName(String firstName, String lastName) return (firstName + " " + lastName); } + + public static String phoneNumber(String phone) + { + if (phone.length() == 10 && phone.charAt(0) == '9') + return ("0" + phone); + else + return ("false"); + } } \ No newline at end of file From 4af4aad858e3a685fe335d4f3a0b0de7d20e89d6 Mon Sep 17 00:00:00 2001 From: Hossein Date: Mon, 18 Mar 2024 20:40:09 +0330 Subject: [PATCH 06/14] add userId method --- Answers/40230112123/src/ResumeMaker.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Answers/40230112123/src/ResumeMaker.java b/Answers/40230112123/src/ResumeMaker.java index d9dc3e0..25fb94b 100644 --- a/Answers/40230112123/src/ResumeMaker.java +++ b/Answers/40230112123/src/ResumeMaker.java @@ -28,4 +28,12 @@ public static String phoneNumber(String phone) else return ("false"); } + + public static boolean userId(String id) + { + if(4 <= id.length() && id.length() <= 13) + return true; + else + return false; + } } \ No newline at end of file From 7e9efdd38511e51cf2959939cab66b85706b405c Mon Sep 17 00:00:00 2001 From: Hossein Date: Mon, 18 Mar 2024 21:03:22 +0330 Subject: [PATCH 07/14] add getInterests method --- Answers/40230112123/src/ResumeMaker.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Answers/40230112123/src/ResumeMaker.java b/Answers/40230112123/src/ResumeMaker.java index 25fb94b..e369d0f 100644 --- a/Answers/40230112123/src/ResumeMaker.java +++ b/Answers/40230112123/src/ResumeMaker.java @@ -1,3 +1,5 @@ +// Resume Maker : A simple program for make a resume + public class ResumeMaker { public static void main(String[] args) @@ -36,4 +38,12 @@ public static boolean userId(String id) else return false; } + + public static String[] getInterests(String... interests) + { + String[] interestArray = new String[interests.length]; + for (int i = 0; i < interests.length; i++) + interestArray[i] = interests[i]; + return interestArray; + } } \ No newline at end of file From 7eabba213476a9cb1f3cc53097bcdffddf19469f Mon Sep 17 00:00:00 2001 From: Hossein Date: Mon, 18 Mar 2024 21:34:35 +0330 Subject: [PATCH 08/14] add userFullInformation method --- Answers/40230112123/src/ResumeMaker.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Answers/40230112123/src/ResumeMaker.java b/Answers/40230112123/src/ResumeMaker.java index e369d0f..91cbbd1 100644 --- a/Answers/40230112123/src/ResumeMaker.java +++ b/Answers/40230112123/src/ResumeMaker.java @@ -1,4 +1,5 @@ // Resume Maker : A simple program for make a resume +import java.security.SecureRandom; public class ResumeMaker { @@ -46,4 +47,14 @@ public static String[] getInterests(String... interests) interestArray[i] = interests[i]; return interestArray; } + + public static void userFullInformation(String fullName, String phoneNumber, String userId, + String[] interests) + { + System.out.printf("Hello! My name is %s . My ID is %s. ", fullName, userId); + System.out.printf("Here are some of my interests:%n"); + for (int i = 0; i < interests.length; i++) + System.out.printf("%d. %s%n", i, interests[i]); + System.out.printf("%nYou can reach me via my phone number %s.", phoneNumber); + } } \ No newline at end of file From 3bb27b770d322fb52a46354bb782f09560f7179a Mon Sep 17 00:00:00 2001 From: Hossein Date: Mon, 18 Mar 2024 21:47:43 +0330 Subject: [PATCH 09/14] add informationEncoder method --- Answers/40230112123/src/ResumeMaker.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Answers/40230112123/src/ResumeMaker.java b/Answers/40230112123/src/ResumeMaker.java index 91cbbd1..8549e47 100644 --- a/Answers/40230112123/src/ResumeMaker.java +++ b/Answers/40230112123/src/ResumeMaker.java @@ -57,4 +57,26 @@ public static void userFullInformation(String fullName, String phoneNumber, Stri System.out.printf("%d. %s%n", i, interests[i]); System.out.printf("%nYou can reach me via my phone number %s.", phoneNumber); } + + public static void informationEncoder(String information, int shift) + { + String encodeInformation = new String[information.length()]; + for (int i = 0; i < information.length(); i++) + { + char character = information[i]; + if ('A' <= character && character <= 'Z') + { + character += shift; + if(character > 'Z') + character -= 26; // 26 letters of En alphabetic + } else if ('a' <= character && character <= 'z') + { + character += shift; + if(character > 'z') + character -= 26; // 26 letters in En alphabetic + } + encodeInformation[i] = character; + } + System.out.println(encodeInformation); + } } \ No newline at end of file From 36e1176fe3af8131d28c998509dbe2eb3d6efe3e Mon Sep 17 00:00:00 2001 From: Hossein Date: Mon, 18 Mar 2024 21:55:52 +0330 Subject: [PATCH 10/14] add informationEncoder method --- Answers/40230112123/src/ResumeMaker.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Answers/40230112123/src/ResumeMaker.java b/Answers/40230112123/src/ResumeMaker.java index 8549e47..d946595 100644 --- a/Answers/40230112123/src/ResumeMaker.java +++ b/Answers/40230112123/src/ResumeMaker.java @@ -58,7 +58,7 @@ public static void userFullInformation(String fullName, String phoneNumber, Stri System.out.printf("%nYou can reach me via my phone number %s.", phoneNumber); } - public static void informationEncoder(String information, int shift) + public static String[] informationEncoder(String information, int shift) { String encodeInformation = new String[information.length()]; for (int i = 0; i < information.length(); i++) @@ -77,6 +77,6 @@ public static void informationEncoder(String information, int shift) } encodeInformation[i] = character; } - System.out.println(encodeInformation); + return encodeInformation; } } \ No newline at end of file From 8cbf3291d1c4a2c9fc5f4cf79f240673e5cb9cf5 Mon Sep 17 00:00:00 2001 From: Hossein Date: Mon, 18 Mar 2024 22:04:33 +0330 Subject: [PATCH 11/14] add informationDecoder method --- Answers/40230112123/src/ResumeMaker.java | 27 +++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Answers/40230112123/src/ResumeMaker.java b/Answers/40230112123/src/ResumeMaker.java index d946595..34aa1a8 100644 --- a/Answers/40230112123/src/ResumeMaker.java +++ b/Answers/40230112123/src/ResumeMaker.java @@ -58,9 +58,10 @@ public static void userFullInformation(String fullName, String phoneNumber, Stri System.out.printf("%nYou can reach me via my phone number %s.", phoneNumber); } - public static String[] informationEncoder(String information, int shift) + public static String informationEncoder(String information, int shift) { String encodeInformation = new String[information.length()]; + for (int i = 0; i < information.length(); i++) { char character = information[i]; @@ -77,6 +78,30 @@ public static String[] informationEncoder(String information, int shift) } encodeInformation[i] = character; } + return encodeInformation; } + + public static String informationDecoder(String information, int shift) + { + String decodeInformation = new String[information.length()]; + + for (int i = 0; i < information.length(); i++) + { + if ('A' <= character && character <= 'Z') + { + character -= shift; + if(character < 'A') + character += 26; // 26 letters of En alphabetic + } else if ('a' <= character && character <= 'z') + { + character -= shift; + if(character < 'a') + character += 26; // 26 letters in En alphabetic + } + decodeInformation[i] = character; + } + + return decodeInformation; + } } \ No newline at end of file From 07c3a5b9250758acc1468dd58910da6168b5df68 Mon Sep 17 00:00:00 2001 From: Hossein Date: Mon, 18 Mar 2024 22:50:02 +0330 Subject: [PATCH 12/14] add main method --- Answers/40230112123/src/ResumeMaker.java | 58 +++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/Answers/40230112123/src/ResumeMaker.java b/Answers/40230112123/src/ResumeMaker.java index 34aa1a8..5817f1b 100644 --- a/Answers/40230112123/src/ResumeMaker.java +++ b/Answers/40230112123/src/ResumeMaker.java @@ -1,13 +1,69 @@ // Resume Maker : A simple program for make a resume import java.security.SecureRandom; +import java.util.Scanner; +import java.util.Arrays; public class ResumeMaker { public static void main(String[] args) { + Scanner input = new Scanner(System.in); + System.out.println("Enter the following information below: "); + // input name + System.out.print("your first name: "); + String firstName = input.nextLine(); + + System.out.print("your last name: "); + String lastName = input.nextLine(); + + // store the full name of person + String name = fullName(firstName, lastName); + System.out.println("your name saved."); + + // input phone number + System.out.print("your phone number: "); + String phone; + while (true) + { + phone = input.nextLine(); + phone = phoneNumber(phone); + if (Arrays.equals(phone, "false")) + System.out.println("Wrong entry. Try again."); + else + { + System.out.println("your phone saved."); + break; + } + } + + // input user id + System.out.println("your user ID: "); + String id; + while (true) + { + id = input.nextLine(); + if (userId(id)) + { + System.out.println("your ID saved."); + break; + } + else + System.out.println("ID should be between 4 to 13 digits. Try again."); + } + + // input interests + String interest; + System.out.println("your interests(comma seperated list): "); + interest = input.nextLine(); + String[] interests = getInterests(interest); + + // show menu + menu(); } + + public static String fullName(String firstName, String lastName) { firstName = firstName.toLowerCase(); @@ -40,7 +96,7 @@ public static boolean userId(String id) return false; } - public static String[] getInterests(String... interests) + public static String[] getInterests(String interests) { String[] interestArray = new String[interests.length]; for (int i = 0; i < interests.length; i++) From d376440495fa40fc897f7f9e62f54efbcfd2e7eb Mon Sep 17 00:00:00 2001 From: Hossein Date: Mon, 18 Mar 2024 23:19:58 +0330 Subject: [PATCH 13/14] add menu method --- Answers/40230112123/src/ResumeMaker.java | 55 ++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/Answers/40230112123/src/ResumeMaker.java b/Answers/40230112123/src/ResumeMaker.java index 5817f1b..a707c67 100644 --- a/Answers/40230112123/src/ResumeMaker.java +++ b/Answers/40230112123/src/ResumeMaker.java @@ -59,10 +59,57 @@ public static void main(String[] args) String[] interests = getInterests(interest); // show menu - menu(); + menu(name, phone, id, interests); } - + public static void menu(String fullName, String phoneNumber, String userId, + String[] interests) + { + Scanner input = new Scanner(System.in); + while (true) + { + int choice; + System.out.printf("%n1. full information%n2. encode information%n"); + System.out.printf("3. decode information%n4. exit%n"); + System.out.print("%nPlease eneter your choice(1-4): "); + choice = input.nextInt(); + + // select the choice + switch (choice) + { + case 1: + userFullInformation(fullName, phoneNumber, userId, interests); + break; + case 2: + System.out.println("Enter a string to encode: "); + String code = input.nextLine(); + System.out.print("Enter the number to shift encode information(0 : random number): "); + int shift = input.nextInt(); + if (shift == 0) + { + SecureRandom randomNumber = new SecureRandom(); + shift = 1 + randomNumber.nextInt(25); + } + informationEncoder(code, shift); + break; + case 3: + System.out.println("Enter a string to decode: "); + String decode = input.nextLine(); + System.out.print("Enter the shift number: "); + int shift = input.nextInt(); + informationDecoder(decode, shift); + break; + case 4: + System.out.print("press enter to exit..."); + input.nextLine(); + return; + default: + System.out.println("invalid number!"); + } + System.out.print("press enter to continue..."); + input.nextLine(); + } + } public static String fullName(String firstName, String lastName) { @@ -114,7 +161,7 @@ public static void userFullInformation(String fullName, String phoneNumber, Stri System.out.printf("%nYou can reach me via my phone number %s.", phoneNumber); } - public static String informationEncoder(String information, int shift) + public static void informationEncoder(String information, int shift) { String encodeInformation = new String[information.length()]; @@ -135,7 +182,7 @@ public static String informationEncoder(String information, int shift) encodeInformation[i] = character; } - return encodeInformation; + System.out.printf("%nCode information : %s%n", encodeInformation); } public static String informationDecoder(String information, int shift) From 563d002d25ff0585a14f5a991f274ad7f1297a0f Mon Sep 17 00:00:00 2001 From: Hossein Date: Tue, 19 Mar 2024 00:58:44 +0330 Subject: [PATCH 14/14] debug application --- Answers/40230112123/src/ResumeMaker.java | 70 ++++++++++++------------ 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/Answers/40230112123/src/ResumeMaker.java b/Answers/40230112123/src/ResumeMaker.java index a707c67..ade24e3 100644 --- a/Answers/40230112123/src/ResumeMaker.java +++ b/Answers/40230112123/src/ResumeMaker.java @@ -1,7 +1,6 @@ // Resume Maker : A simple program for make a resume import java.security.SecureRandom; import java.util.Scanner; -import java.util.Arrays; public class ResumeMaker { @@ -28,7 +27,7 @@ public static void main(String[] args) { phone = input.nextLine(); phone = phoneNumber(phone); - if (Arrays.equals(phone, "false")) + if (phone.equals("false")) System.out.println("Wrong entry. Try again."); else { @@ -38,7 +37,7 @@ public static void main(String[] args) } // input user id - System.out.println("your user ID: "); + System.out.print("your user ID: "); String id; while (true) { @@ -54,7 +53,7 @@ public static void main(String[] args) // input interests String interest; - System.out.println("your interests(comma seperated list): "); + System.out.print("your interests(comma separated list): "); interest = input.nextLine(); String[] interests = getInterests(interest); @@ -66,48 +65,45 @@ public static void menu(String fullName, String phoneNumber, String userId, String[] interests) { Scanner input = new Scanner(System.in); + String code = "Hello! My name is " + fullName + + ".I like " + interests[0] + "."; + String decode = ""; + int shift = 0; // shift value + while (true) { int choice; System.out.printf("%n1. full information%n2. encode information%n"); System.out.printf("3. decode information%n4. exit%n"); - System.out.print("%nPlease eneter your choice(1-4): "); + System.out.printf("%nPlease enter your choice(1-4): "); choice = input.nextInt(); // select the choice - switch (choice) - { + switch (choice) { case 1: userFullInformation(fullName, phoneNumber, userId, interests); break; case 2: - System.out.println("Enter a string to encode: "); - String code = input.nextLine(); System.out.print("Enter the number to shift encode information(0 : random number): "); - int shift = input.nextInt(); - if (shift == 0) - { + shift = input.nextInt(); + if (shift == 0) { SecureRandom randomNumber = new SecureRandom(); shift = 1 + randomNumber.nextInt(25); + System.out.printf("Shift number is %d%n", shift); } - informationEncoder(code, shift); + decode = informationEncoder(code, shift); break; case 3: - System.out.println("Enter a string to decode: "); - String decode = input.nextLine(); - System.out.print("Enter the shift number: "); - int shift = input.nextInt(); - informationDecoder(decode, shift); + if (decode.equals("")) + System.out.println("You should first code your information."); + else + informationDecoder(decode, shift); break; case 4: - System.out.print("press enter to exit..."); - input.nextLine(); return; default: System.out.println("invalid number!"); } - System.out.print("press enter to continue..."); - input.nextLine(); } } @@ -145,29 +141,27 @@ public static boolean userId(String id) public static String[] getInterests(String interests) { - String[] interestArray = new String[interests.length]; - for (int i = 0; i < interests.length; i++) - interestArray[i] = interests[i]; + String[] interestArray = interests.split(","); return interestArray; } public static void userFullInformation(String fullName, String phoneNumber, String userId, String[] interests) { - System.out.printf("Hello! My name is %s . My ID is %s. ", fullName, userId); + System.out.printf("Hello! My name is %s. My ID is %s. ", fullName, userId); System.out.printf("Here are some of my interests:%n"); for (int i = 0; i < interests.length; i++) - System.out.printf("%d. %s%n", i, interests[i]); - System.out.printf("%nYou can reach me via my phone number %s.", phoneNumber); + System.out.printf("%d. %s%n", i + 1, interests[i]); + System.out.printf("%nYou can reach me via my phone number %s.%n", phoneNumber); } - public static void informationEncoder(String information, int shift) + public static String informationEncoder(String information, int shift) { - String encodeInformation = new String[information.length()]; + String encodeInformation = ""; for (int i = 0; i < information.length(); i++) { - char character = information[i]; + char character = information.charAt(i); if ('A' <= character && character <= 'Z') { character += shift; @@ -179,18 +173,19 @@ public static void informationEncoder(String information, int shift) if(character > 'z') character -= 26; // 26 letters in En alphabetic } - encodeInformation[i] = character; + encodeInformation = encodeInformation + character; } - System.out.printf("%nCode information : %s%n", encodeInformation); + return encodeInformation; } - public static String informationDecoder(String information, int shift) + public static void informationDecoder(String information, int shift) { - String decodeInformation = new String[information.length()]; + char[] decodeInformation = new char[information.length()]; for (int i = 0; i < information.length(); i++) { + char character = information.charAt(i); if ('A' <= character && character <= 'Z') { character -= shift; @@ -205,6 +200,9 @@ public static String informationDecoder(String information, int shift) decodeInformation[i] = character; } - return decodeInformation; + System.out.printf("%nDecode information : "); + for (char character : decodeInformation) + System.out.print(character); + System.out.println(); } } \ No newline at end of file