From 9e3ee8923ed3c4ee48aa6f07e6636c4fc1292dd2 Mon Sep 17 00:00:00 2001 From: mosalehrabbani <155375059+mosalehrabbani@users.noreply.github.com> Date: Thu, 21 Mar 2024 05:54:00 +0330 Subject: [PATCH 1/2] task done --- .idea/.gitignore | 3 + .idea/Functions-Introduction.iml | 9 + .idea/inspectionProfiles/Project_Default.xml | 6 + .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + Answers/Main/.gitignore | 29 +++ Answers/Main/.idea/.gitignore | 3 + Answers/Main/.idea/.name | 1 + Answers/Main/.idea/misc.xml | 6 + Answers/Main/.idea/modules.xml | 8 + Answers/Main/.idea/vcs.xml | 6 + Answers/Main/Main.iml | 11 + Answers/Main/src/Main.java | 217 +++++++++++++++++++ 14 files changed, 319 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/Functions-Introduction.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Answers/Main/.gitignore create mode 100644 Answers/Main/.idea/.gitignore create mode 100644 Answers/Main/.idea/.name create mode 100644 Answers/Main/.idea/misc.xml create mode 100644 Answers/Main/.idea/modules.xml create mode 100644 Answers/Main/.idea/vcs.xml create mode 100644 Answers/Main/Main.iml create mode 100644 Answers/Main/src/Main.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Functions-Introduction.iml b/.idea/Functions-Introduction.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Functions-Introduction.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..29a4116 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..95e372b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Answers/Main/.gitignore b/Answers/Main/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Answers/Main/.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/Main/.idea/.gitignore b/Answers/Main/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Answers/Main/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Answers/Main/.idea/.name b/Answers/Main/.idea/.name new file mode 100644 index 0000000..002da1d --- /dev/null +++ b/Answers/Main/.idea/.name @@ -0,0 +1 @@ +Main.java \ No newline at end of file diff --git a/Answers/Main/.idea/misc.xml b/Answers/Main/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/Answers/Main/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Answers/Main/.idea/modules.xml b/Answers/Main/.idea/modules.xml new file mode 100644 index 0000000..f261f71 --- /dev/null +++ b/Answers/Main/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Answers/Main/.idea/vcs.xml b/Answers/Main/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/Answers/Main/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Answers/Main/Main.iml b/Answers/Main/Main.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Answers/Main/Main.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/Main/src/Main.java b/Answers/Main/src/Main.java new file mode 100644 index 0000000..8624a2a --- /dev/null +++ b/Answers/Main/src/Main.java @@ -0,0 +1,217 @@ +import java.util.Scanner; +import java.util.Objects; +import javax.management.BadStringOperationException; + +public class Main{ + static boolean F = true; + public static String fullName(String firstName, String lastName){ + firstName = firstName.toLowerCase(); + lastName = lastName.toLowerCase(); + String[] name1 = firstName.split(""); + String[] last1 = lastName.split(""); + name1[0] = name1[0].toUpperCase(); + last1[0] = last1[0].toUpperCase(); + String res = "" ; + for(int i =0 ; i< name1.length ;i++) + res += name1[i]; + res += " "; + for(int i =0 ; i< last1.length ;i++) { + res += last1[i]; + } + return res.trim() ; + } + public static String phoneNumber(long phone){ + int count; + long n = phone; + for(count=0 ; n /10 != 0; count++) + { + n = n/10 ; + } + count ++; + if (count != 10){ + F = true; + return "f" ; + } + int size; + String phone1 = String.valueOf(phone); + String[] phone2 = phone1.split(""); + size = phone2.length; + if (phone2[0] != "9") { + String[] res = new String[size+1]; + res[0]="0"; + for (int i=0 ; i13){ + F = true; + return "f" ; + } + String id1 = String.valueOf(id); + F = false; + return id1; + } + public static String getInterests(){ + Scanner scan = new Scanner(System.in); + String[] interests = new String[11]; + boolean flag = true; + int i =0 ; + System.out.println("If you want it to end, write \"finish\""); + while (flag && i<10){ + System.out.println("enter your interest: "); + interests[i] =scan.nextLine(); + if (Objects.equals(interests[i], "finish")){ + flag =false; + continue; + } + i++; + } + String res=""; + for (int j = 0; !Objects.equals(interests[j], "finish") && (j < 10); j++){ + res = res + ((j+1) + ". " + interests[j]+"\n"); + } + return res; + } + public static String userFullInformation(String fullName, String phoneNumber,String userID, String interests){ + String res = "Hello! My name is "+fullName+"."+" My ID is "+userID+"."+" Here are some of my interests:"+"\n"+interests + "\n"+"You can reach me via my phone number "+phoneNumber; +// System.out.println("Hello! My name is " +// +fullName+"."+" My ID is "+userID+"."+" Here are some of my interests:"); +// System.out.println(interests); +// System.out.println("You can reach me via my phone number "+phoneNumber); + return res; + } + + public static void informationDecoder(String information, int shift){ + char[] information1 = information.toCharArray(); + char[] information2 = new char[information1.length]; + int n; + for (int i=0 ; i< information1.length;i++){ + n = information1[i] - shift; + if ((information1[i] >=65 && information1[i] <=90 ) && n<65){ + information2[i] = (char) (91+n-65); + } + else if ((information1[i] >96 && information1[i] <123) && n <= 96){ + information2[i] = (char) (122 +(n-96)) ; + } + else if ((information1[i] >96 && information1[i] <123) && ((n > 96 && n < 123))){ // tik + information2[i] = (char) n; + + } + else if ((information1[i] >=65 && information1[i] <=90 ) && ((n>=65 && n <=90))) { + information2[i] = (char) n ; + } + else { + information2[i] = information1[i]; + } + } + for (int i=0 ; i < information2.length;i++){ + System.out.print(information2[i]); + } + } + + public static String informationEncoder( String information,int shift){ + char[] information1 = information.toCharArray(); + char[] information2 = new char[information1.length]; + int n; + for (int i=0 ; i < information1.length ; i++){ + n = information1[i] + shift; + if ((information1[i] >=65 && information1[i] <=90 ) && n > 90 ){ + information2[i] = (char) (64 + (n-90)); + } + else if((information1[i] >96 && information1[i] <123) && n >122){ + information2[i] = (char) (96+(n-122)); + } + else if ((information1[i] >=65 && information1[i] <=90 ) && (n>=65 && n<=90)){ + information2[i] = (char) n ; + } + else if ((information1[i] >96 && information1[i] <123) && (n>96 && n<123)){ + information2[i] = (char) n ; + } + else{ + information2[i] = information1[i]; + } + } + String res=""; + for (int i=0 ; i < information2.length;i++){ + res += information2[i]; + System.out.print(information2[i]); + } + return res; + } + public static void main (String[] args){ + Scanner scan = new Scanner(System.in); + System.out.print("First name: "); + String firstName = scan.nextLine(); + System.out.print("Last name: "); + String lastName = scan.nextLine(); + String fullName = fullName(firstName , lastName); + String phoneNumber = new String(); + String ID = new String(); + while (F) { + System.out.print("Phone number (do not insert first zero) : 0"); + long phone = scan.nextLong(); + phoneNumber = phoneNumber(phone); + } + F = true; + while (F) { + System.out.print("User ID: "); + long id = scan.nextLong(); + ID = userId(id); + } + F = true; + String interests = getInterests(); + String result = userFullInformation(fullName,phoneNumber,ID,interests); + System.out.println(result); + while (F){ + int shift; + System.out.println("do you want to coding information? (y/n)"); + String c = scan.next(); + if (Objects.equals(c, "y")){ + System.out.print("how many step you want to shift: "); + shift = scan.nextInt(); + result=informationEncoder(result,shift); + System.out.println("\n"); + } + else{ + break; + } + System.out.println("do you want to decoding information? (y/n)"); + c = scan.next(); + if (Objects.equals(c, "y")){ + informationDecoder(result,shift); + } + else { + break; + } + + + + + + + + + } + + } + +} \ No newline at end of file From c07ea9596a0bfcdbddbcc6b03866cf180cb53a09 Mon Sep 17 00:00:00 2001 From: mosalehrabbani <155375059+mosalehrabbani@users.noreply.github.com> Date: Thu, 21 Mar 2024 06:03:28 +0330 Subject: [PATCH 2/2] Update Main.java --- Answers/Main/src/Main.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Answers/Main/src/Main.java b/Answers/Main/src/Main.java index 8624a2a..a1433f5 100644 --- a/Answers/Main/src/Main.java +++ b/Answers/Main/src/Main.java @@ -202,16 +202,6 @@ public static void main (String[] args){ else { break; } - - - - - - - - } - } - } \ No newline at end of file