diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..2dac8ce Binary files /dev/null and b/.DS_Store differ diff --git a/Answers/.DS_Store b/Answers/.DS_Store new file mode 100644 index 0000000..8ce0c7b Binary files /dev/null and b/Answers/.DS_Store differ diff --git a/Answers/40230112089/.gitignore b/Answers/40230112089/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Answers/40230112089/.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/40230112089/.idea/misc.xml b/Answers/40230112089/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/Answers/40230112089/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Answers/40230112089/.idea/modules.xml b/Answers/40230112089/.idea/modules.xml new file mode 100644 index 0000000..e0a91e6 --- /dev/null +++ b/Answers/40230112089/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112089/.idea/vcs.xml b/Answers/40230112089/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/Answers/40230112089/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Answers/40230112089/.idea/workspace.xml b/Answers/40230112089/.idea/workspace.xml new file mode 100644 index 0000000..1dcc4f8 --- /dev/null +++ b/Answers/40230112089/.idea/workspace.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1710618949349 + + + + + + \ No newline at end of file diff --git a/Answers/40230112089/Tamrin2.iml b/Answers/40230112089/Tamrin2.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Answers/40230112089/Tamrin2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112089/src/Functions.java b/Answers/40230112089/src/Functions.java new file mode 100644 index 0000000..d7ffdf8 --- /dev/null +++ b/Answers/40230112089/src/Functions.java @@ -0,0 +1,115 @@ +import java.util.ArrayList; +import java.util.regex.Pattern; + +public class Functions { + + + public String fullName(String fName, String lName) { + String resultFName = fName.substring(0, 1).toUpperCase() + fName.substring(1).toLowerCase(); + String resultLName = lName.substring(0, 1).toUpperCase() + lName.substring(1).toLowerCase(); + + + return resultFName + ' ' + resultLName; + } + + public String phoneNumber(String phone) { + char characterAtIndex0 = phone.charAt(0); + int phoneSize = phone.length(); + if (characterAtIndex0 == '9' && phoneSize == 10 && phone.matches("[0-9]+")) { + return '0' + phone; + } else { + return "Wrong entry. Try again."; + } + } + + public String userId(String id) { + int idSize = id.length(); + + if (idSize >= 4 && idSize <= 13 && id.matches("[0-9]+")) { + return id; + } else { + return "Wrong entry. Try again."; + } + + } + + public StringBuilder getInterests(ArrayList interests) { + + StringBuilder result4 = new StringBuilder(); + result4.append('{'); + for (int i = 0; i < interests.size(); i++) { + result4.append('"').append(interests.get(i)).append('"'); + if (i != interests.size() - 1) { + result4.append(", "); + } + } + result4.append('}'); + return result4; + } + + public StringBuilder userFullInformation(String fullName, String phoneNumber, String userID, ArrayList interests) { + StringBuilder userFullInformation =new StringBuilder(); + userFullInformation.append(" Hello! My name is " + fullName + ". My ID is " + userID + ". Here are some of my interests:\n"); + for (int i = 0; i < interests.size(); i++) { + userFullInformation.append(i + 1 + ". " + interests.get(i) + "\n"); + } + userFullInformation.append("You can reach me via my phone number " + phoneNumber + "."); + return userFullInformation; + } + + public String informationEncoder(String information, int shift) { + StringBuilder newString = new StringBuilder(); + for (int i = 0; i < information.length(); i++) { + if (information.charAt(i) > 96 && information.charAt(i) < 123) { //اگر حروف کوچک بود + if (information.charAt(i) + shift < 123) { + char newChar = (char) (information.charAt(i) + shift); + newString.append(newChar); + } else { + char newChar = (char) (96 + ((information.charAt(i) + shift) - 122)); + newString.append(newChar); + } + } else if (information.charAt(i) > 64 && information.charAt(i) < 91) { + if (information.charAt(i) + shift < 91) { + char newChar = (char) (information.charAt(i) + shift); + newString.append(newChar); + } else { + char newChar = (char) (64 + ((information.charAt(i) + shift) - 90)); + newString.append(newChar); + } + } else { + newString.append(information.charAt(i)); + } + + } + return newString.toString(); + } + + + public String informationDecoder(String information , int shift){ + StringBuilder newString = new StringBuilder(); + for (int i = 0; i < information.length(); i++) { + if (information.charAt(i) > 96 && information.charAt(i) < 123) { //اگر حروف کوچک بود + if (information.charAt(i) - shift >96) { + char newChar = (char) (information.charAt(i) - shift); + newString.append(newChar); + } else { + char newChar = (char) (123 + ((information.charAt(i) - shift) - 97)); + newString.append(newChar); + } + } else if (information.charAt(i) > 64 && information.charAt(i) < 91) { + if (information.charAt(i) - shift >64) { + char newChar = (char) (information.charAt(i) - shift); + newString.append(newChar); + } else { + char newChar = (char) (91 + ((information.charAt(i) - shift) - 65)); + newString.append(newChar); + } + } else { + newString.append(information.charAt(i)); + } + + } + return newString.toString(); + } + } + diff --git a/Answers/40230112089/src/Main.java b/Answers/40230112089/src/Main.java new file mode 100644 index 0000000..409d6aa --- /dev/null +++ b/Answers/40230112089/src/Main.java @@ -0,0 +1,128 @@ +import java.net.SocketTimeoutException; +import java.util.Scanner; +import java.util.ArrayList; + +// Press ⇧ twice to open the Search Everywhere dialog and type `show whitespaces`, +// then press Enter. You can now see whitespace characters in your code. +public class Main { + + public static void main(String[] args) { + Scanner scStr = new Scanner(System.in); + Scanner scInt = new Scanner(System.in); + + + + + System.out.println("Please enter your first name:"); + String fName = scStr.nextLine(); + System.out.println("Please enter your last name:"); + String lName = scStr.nextLine(); + + Functions functions = new Functions(); + + String userFullName = functions.fullName(fName, lName); + System.out.println(userFullName); + + + System.out.println("Please enter your phone number:"); + + boolean invalid =true; + String userPhoneNumber = ""; + while(invalid) { + String phoneNumber = scInt.nextLine(); + userPhoneNumber = functions.phoneNumber(phoneNumber); + System.out.println(userPhoneNumber); + if (userPhoneNumber !="Wrong entry. Try again."){ + invalid = false; + } + } + + + + + System.out.println("Please Enter your student ID:"); + invalid =true; + + String userId =""; + while(invalid) { + String id = scStr.nextLine(); + + userId = functions.userId(id); + System.out.println(userId); + if (userId !="Wrong entry. Try again."){ + invalid = false; + } + } + + + + System.out.println("Please enter some of your interests: \n(the maximum number of your interests can be 10 and press an extra ENTER button to finish.)"); + + ArrayList interests = new ArrayList<>(); + for (int i=0;i<10;i++){ + String interest = scStr.nextLine(); + if (interest.isEmpty()){ + break; + } + else{ + interests.add(interest); + } + + } + StringBuilder userInterests = functions.getInterests(interests) ; + System.out.println(userInterests); + + + StringBuilder userFullInformation = functions.userFullInformation(userFullName, userPhoneNumber, userId, interests); + + + + + + System.out.println("Please enter information for encode: "); + String Information1 = scStr.nextLine(); + System.out.println("Please enter the number of shifts:"); + int shift1 = scInt.nextInt(); + + String informationEncoder = functions.informationEncoder(Information1 , shift1); + System.out.println(informationEncoder); + + + + System.out.println("Please enter encode information to decode: "); + String Information2 = scStr.nextLine(); + System.out.println("Please enter the number of shifts:"); + int shift2 = scInt.nextInt(); + + String informationDecoder = functions.informationDecoder(Information2 , shift2); + System.out.println(informationDecoder); + + + String encodedInformation = functions.informationEncoder(userFullInformation.toString() , 3); + while (true){ + System.out.println("Please select an option :"); + System.out.println("1. show encoded information"); + System.out.println("2. show decoded information"); + System.out.println("3. exit"); + String choice = scStr.nextLine(); + switch (choice){ + case "1" : + System.out.println(encodedInformation); + break; + case "2" : + System.out.println(functions.informationDecoder(encodedInformation , 3)); + break; + case "3" : + System.out.println("Bye :)"); + System.exit(0); + break; + default: + System.exit(0); + } + } + + + } + + +} \ No newline at end of file