From 920a2b8de7cc8399a3f3eaee5d99d637ecf4d1a8 Mon Sep 17 00:00:00 2001 From: The Navid Date: Tue, 19 Mar 2024 18:57:08 +0330 Subject: [PATCH 1/7] fullName --- .../40230212013/functionsIntroduction.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Answers/40230212013/functionsIntroduction.java diff --git a/Answers/40230212013/functionsIntroduction.java b/Answers/40230212013/functionsIntroduction.java new file mode 100644 index 0000000..b837079 --- /dev/null +++ b/Answers/40230212013/functionsIntroduction.java @@ -0,0 +1,20 @@ +import java.util.Scanner; + +public class functionsIntroduction { + public static String fullName(String firstName , String lastName) + { + return capitalizeFirstLetter(firstName)+ " "+ capitalizeFirstLetter(lastName); + } + private static String capitalizeFirstLetter(String str) + { + return str.substring(0,1).toUpperCase() + str.substring(1).toLowerCase(); + } + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + System.out.println("Enter your First Name: "); + String firstName = input.nextLine(); + System.out.println("Enter your Last Name: "); + String lastName = input.nextLine(); + String fullName = fullName(firstName, lastName); + } +} From fe72c56b54be74cc70623fb76386cbb5a14e5b21 Mon Sep 17 00:00:00 2001 From: The Navid Date: Tue, 19 Mar 2024 20:01:49 +0330 Subject: [PATCH 2/7] phoneNumber --- Answers/40230212013/functionsIntroduction.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Answers/40230212013/functionsIntroduction.java b/Answers/40230212013/functionsIntroduction.java index b837079..831378e 100644 --- a/Answers/40230212013/functionsIntroduction.java +++ b/Answers/40230212013/functionsIntroduction.java @@ -9,6 +9,16 @@ private static String capitalizeFirstLetter(String str) { return str.substring(0,1).toUpperCase() + str.substring(1).toLowerCase(); } + /********************************************************************************************************************************************************************************** */ + public static String phoneNumber(String phone) { + if (phone.length() == 10 && phone.startsWith("9")) { + return "0" + phone; + } else { + System.out.println("Wrong entry. Try again."); + return phoneNumber(new Scanner(System.in).nextLine()); + } + } + public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter your First Name: "); @@ -16,5 +26,8 @@ public static void main(String[] args) { System.out.println("Enter your Last Name: "); String lastName = input.nextLine(); String fullName = fullName(firstName, lastName); + System.out.println("Enter your Phone Number: "); + String phone = phoneNumber(input.nextLine()); + } } From 3d396918f9327ce33b76ed4328a5debfa1dc97b8 Mon Sep 17 00:00:00 2001 From: The Navid Date: Tue, 19 Mar 2024 20:03:12 +0330 Subject: [PATCH 3/7] userId --- Answers/40230212013/functionsIntroduction.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Answers/40230212013/functionsIntroduction.java b/Answers/40230212013/functionsIntroduction.java index 831378e..f9f748a 100644 --- a/Answers/40230212013/functionsIntroduction.java +++ b/Answers/40230212013/functionsIntroduction.java @@ -18,7 +18,19 @@ public static String phoneNumber(String phone) { return phoneNumber(new Scanner(System.in).nextLine()); } } - + /*********************************************************************************************************************************************************************************** */ + public static String userId(String id) + { + if (id.length() <= 4 || id.length() >= 13) + { + return id; + } + else + { + System.out.println("userID should be between 4 to 13 digits. try again."); + return userId(new Scanner(System.in).nextLine()); + } + } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter your First Name: "); @@ -28,6 +40,8 @@ public static void main(String[] args) { String fullName = fullName(firstName, lastName); System.out.println("Enter your Phone Number: "); String phone = phoneNumber(input.nextLine()); - + System.out.println("Enter your ID: "); + String id = userId(scanner.nextLine()); + } } From b9d22b39e2401be276eeb73e952a9d8be3f3b264 Mon Sep 17 00:00:00 2001 From: The Navid Date: Tue, 19 Mar 2024 21:14:03 +0330 Subject: [PATCH 4/7] getInterests --- .../40230212013/functionsIntroduction.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Answers/40230212013/functionsIntroduction.java b/Answers/40230212013/functionsIntroduction.java index f9f748a..eb5eba2 100644 --- a/Answers/40230212013/functionsIntroduction.java +++ b/Answers/40230212013/functionsIntroduction.java @@ -31,6 +31,25 @@ public static String userId(String id) return userId(new Scanner(System.in).nextLine()); } } + /********************************************************************************************************************************************************************************** */ + public static String[] getInterests(int maxInterests) + { + Scanner scanner = new Scanner(System.in); + String[] interests = new String[maxInterests]; + int count = 0; + System.out.println("Enter your interests (max 10):"); + while (count < maxInterests) + { + String interest = scanner.nextLine(); + if (interest.isEmpty()) + { + break; // User finished entering interests + } + interests[count] = interest; + count++; + } + return interests; + } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter your First Name: "); @@ -42,6 +61,7 @@ public static void main(String[] args) { String phone = phoneNumber(input.nextLine()); System.out.println("Enter your ID: "); String id = userId(scanner.nextLine()); + String[] interests = getInterests(10); } } From 60d5b38ab62990204353297064cbed7f8b20f1a6 Mon Sep 17 00:00:00 2001 From: The Navid Date: Thu, 21 Mar 2024 20:52:51 +0330 Subject: [PATCH 5/7] userInformation --- Answers/40230212013/functionsIntroduction.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Answers/40230212013/functionsIntroduction.java b/Answers/40230212013/functionsIntroduction.java index eb5eba2..d4200a9 100644 --- a/Answers/40230212013/functionsIntroduction.java +++ b/Answers/40230212013/functionsIntroduction.java @@ -50,6 +50,18 @@ public static String[] getInterests(int maxInterests) } return interests; } + /********************************************************************************************************************************************************************************** */ + public static String userFullInformation(String fullName, String phone, String id, String[] interests) + { + StringBuilder full = new StringBuilder(); + full.append("Hello! My name is ").append(fullName).append(". My ID is ").append(id).append(". Here are some of my interests:\n"); + for(int i=0; i < interests.length && interests[i] != null; i++) + { + full.append(i+1).append(". ").append(interests[i]).append("\n"); + } + full.append("You can reach me via my phone number ").append(phone).append("\n"); + return full.toString(); + } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter your First Name: "); @@ -62,6 +74,6 @@ public static void main(String[] args) { System.out.println("Enter your ID: "); String id = userId(scanner.nextLine()); String[] interests = getInterests(10); - + String fullInformation = userFullInformation(fullName, phone, id, interests); } } From 079e44b74c6d5f81670036bbc868b5568db85f15 Mon Sep 17 00:00:00 2001 From: The Navid Date: Thu, 21 Mar 2024 21:18:09 +0330 Subject: [PATCH 6/7] informationEncoder --- .../40230212013/functionsIntroduction.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Answers/40230212013/functionsIntroduction.java b/Answers/40230212013/functionsIntroduction.java index d4200a9..217d1e5 100644 --- a/Answers/40230212013/functionsIntroduction.java +++ b/Answers/40230212013/functionsIntroduction.java @@ -62,6 +62,31 @@ public static String userFullInformation(String fullName, String phone, String i full.append("You can reach me via my phone number ").append(phone).append("\n"); return full.toString(); } + /********************************************************************************************************************************************************************************** */ + public static String informationEncoder(String information, int shift) + { + StringBuilder encode = new StringBuilder(); + for(int i = 0 ; i < information.length() ; i++) + { + char c = information.charAt(i); + if(Character.isAlphabetic(c)) + { + int newChar = c+shift; + if(Character.isUpperCase(c)) + { + encode.append((char)(newChar < 'A' ? newChar + 26 : newChar)) + } + else + { + encode.append((char)(newChar < 'a' ? newChar + 26 : newChar)); + } + } + else { + encode.append(c); + } + } + return encode.toString(); + } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter your First Name: "); @@ -75,5 +100,14 @@ public static void main(String[] args) { String id = userId(scanner.nextLine()); String[] interests = getInterests(10); String fullInformation = userFullInformation(fullName, phone, id, interests); + System.out.println("Would you Like to see the encoded information? (y for yes/n for no)"); + String choice = input.nextLine().toLowerCase; + if(choice.equals("y")) + { + System.out.print("How many units should the letters be shifted? (Enter a positive number): "); + int Shift = Integer.parseInt(input.nextLine()); + String encodedIformation = informationEnceoder(fullIformation, shift); + System.out.println(encodedInformation); + } } } From fecc85e7fcddffc4d3cb162154b25d2335ac4845 Mon Sep 17 00:00:00 2001 From: The Navid Date: Fri, 22 Mar 2024 16:37:18 +0330 Subject: [PATCH 7/7] informationDecoder --- .../40230212013/functionsIntroduction.java | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/Answers/40230212013/functionsIntroduction.java b/Answers/40230212013/functionsIntroduction.java index 217d1e5..9c49276 100644 --- a/Answers/40230212013/functionsIntroduction.java +++ b/Answers/40230212013/functionsIntroduction.java @@ -1,5 +1,6 @@ import java.util.Scanner; + public class functionsIntroduction { public static String fullName(String firstName , String lastName) { @@ -21,7 +22,7 @@ public static String phoneNumber(String phone) { /*********************************************************************************************************************************************************************************** */ public static String userId(String id) { - if (id.length() <= 4 || id.length() >= 13) + if (id.length() >= 4 || id.length() <= 13) { return id; } @@ -74,7 +75,7 @@ public static String informationEncoder(String information, int shift) int newChar = c+shift; if(Character.isUpperCase(c)) { - encode.append((char)(newChar < 'A' ? newChar + 26 : newChar)) + encode.append((char)(newChar < 'A' ? newChar + 26 : newChar)); } else { @@ -87,6 +88,11 @@ public static String informationEncoder(String information, int shift) } return encode.toString(); } + /********************************************************************************************************************************************************************************** */ + public static String informationDecoder(String information, int shift) + { + return informationEncoder(information, -shift); + } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter your First Name: "); @@ -97,17 +103,36 @@ public static void main(String[] args) { System.out.println("Enter your Phone Number: "); String phone = phoneNumber(input.nextLine()); System.out.println("Enter your ID: "); - String id = userId(scanner.nextLine()); + String id = userId(input.nextLine()); String[] interests = getInterests(10); String fullInformation = userFullInformation(fullName, phone, id, interests); + while(true) + { System.out.println("Would you Like to see the encoded information? (y for yes/n for no)"); - String choice = input.nextLine().toLowerCase; + String choice = input.nextLine().toLowerCase(); if(choice.equals("y")) { System.out.print("How many units should the letters be shifted? (Enter a positive number): "); - int Shift = Integer.parseInt(input.nextLine()); - String encodedIformation = informationEnceoder(fullIformation, shift); + int shift = Integer.parseInt(input.nextLine()); + String encodedInformation = informationEncoder(fullInformation, shift); System.out.println(encodedInformation); + System.out.println("Would you Like to see the decoded information? (y for yes/n for close the program)"); + String choice2 = input.nextLine().toLowerCase(); + if(choice2.equals("y")) + { + System.out.println(informationDecoder(fullInformation, shift)); + continue; + } + else + { + break; + } + } + else + { + System.out.println(fullInformation); + } } } +}