diff --git a/Answers/How to send.txt b/40230112134/How to send.txt similarity index 100% rename from Answers/How to send.txt rename to 40230112134/How to send.txt diff --git a/40230112134/README.md b/40230112134/README.md new file mode 100644 index 0000000..e57bd50 --- /dev/null +++ b/40230112134/README.md @@ -0,0 +1,99 @@ +# Introduction to Functions + +This time, we want to delve into creating different types of functions and using them in Java. Your task is to implement some functions and use them correctly to reach the program's goal. Let's start with the program. + +## What is the project about? + +In this assignment, we want you to create a simple resume maker. There are some functions to collect the user's information and, at the end, show the user's information. + +## Functions + +Let's talk about functions. + +### fullName(firstName, lastName) + +This function takes two parameters: the first name and last name of the user and returns their full name. This function should correct the format of the user's first name and last name. For example: + +```plaintext +First name: ArYAn +Last name: nourBAKhsh + +Full name: Aryan Nourbakhsh +``` + +### phoneNumber(phone) + +This function receives a phone number, and if the phone number starts with a 9 and is 10 digits long, it returns the phone number and adds a 0 at the beginning. Note: If the entered number is incorrect, the program shouldn't stop, and it should prompt the user to enter another phone number. + +```plaintext +Phone: 9123456789 +Output: 09123456789 + +Phone: 912345 +Output: Wrong entry. Try again. +``` + +### userId(id) + +This function is responsible for student IDs. It checks the format, and if correct, it returns it. If the format is incorrect, it prompts the user for another entry. The userID should be between 4 to 13 digits. + +```plaintext +ID: 40030111111 +Output: 40030111111 +``` + +### getInterests(interests) + +This function gives users interests and returns an array of interests. The maximum number of interests is 10. + +```plaintext +Input: swimming +Input: gym +Input: video games + +Output: {"swimming", "gym", "video games"} +``` + +### userFullInformation(fullName, phoneNumber, userID, interests) + +This function gets user data and returns the full information of the user. + +```plaintext +Full name: Aryan Nourbakhsh +Phone number: 09123456789 +User ID: 40030111111 +Interests: {"swimming", "gym", "video games"} + +Output: Hello! My name is Aryan Nourbakhsh. My ID is 40030111111. Here are some of my interests: +1. Swimming +2. Gym +3. Video games + +You can reach me via my phone number 09123456789. +``` + +### informationEncoder(information, shift) + +In this function, we get user information and use the Caesar algorithm to encrypt the information, returning the result. You can read about the Caesar Cipher [here](https://en.wikipedia.org/wiki/Caesar_cipher). Here is a sample of input and output: + +```plaintext +Information: Hello, my name is Aryanoor. I am learning Java. +Shift: 3 + +Output: Khoor, pb qdph lv Dubdqrru. L dp ohduqlqj Mdyd. +``` + +### informationDecoder(information, shift) + +This function receives an encoded text and decodes it back to readable text, providing the reversed form of the last function. + +```plaintext +Information: Fvb mvbuk tl jvyyljasf. +Shift: 7 + +Output: You found me correctly. +``` + +Note that initially, you should encode the user information, and the user may choose whether to see the encoded details or not. Create a main function to get user information from input and pass them to each function. + +Good luck! \ No newline at end of file diff --git a/40230112134/untitled/.gitignore b/40230112134/untitled/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/40230112134/untitled/.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/40230112134/untitled/.idea/encodings.xml b/40230112134/untitled/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/40230112134/untitled/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/40230112134/untitled/.idea/misc.xml b/40230112134/untitled/.idea/misc.xml new file mode 100644 index 0000000..82dbec8 --- /dev/null +++ b/40230112134/untitled/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/40230112134/untitled/.idea/vcs.xml b/40230112134/untitled/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/40230112134/untitled/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/40230112134/untitled/.idea/workspace.xml b/40230112134/untitled/.idea/workspace.xml new file mode 100644 index 0000000..e9f0368 --- /dev/null +++ b/40230112134/untitled/.idea/workspace.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + { + "associatedIndex": 7 +} + + + + + + + + + + + + + + + + + + + + + 1710606526420 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/40230112134/untitled/pom.xml b/40230112134/untitled/pom.xml new file mode 100644 index 0000000..d69c9eb --- /dev/null +++ b/40230112134/untitled/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + untitled + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/40230112134/untitled/src/main/java/org/example/Homa.java b/40230112134/untitled/src/main/java/org/example/Homa.java new file mode 100644 index 0000000..58e7005 --- /dev/null +++ b/40230112134/untitled/src/main/java/org/example/Homa.java @@ -0,0 +1,229 @@ +package org.example; + +import java.util.Arrays; +import java.util.Objects; +import java.util.Scanner; + +public class Homa { + public static void main(String[] Amir) + { + System.out.println("first enter your information"); + String[] Information = userFullInformation(); + MainPage(Information); + } + static void MainPage(String[] Information) + { + System.out.println("Choose your path"); + System.out.println("1.Encoded your information"); + System.out.println("2.Decoded your information"); + System.out.println("3.Exit"); + Scanner SC = new Scanner(System.in); + int way = SC.nextInt(); + boolean flag = false; + while (flag == false) + { + switch (way) + { + case 1: + informationEncoder(Information); + flag = true; + break; + case 2: + informationDecoder(Information); + flag = true; + break; + case 3: + System.out.println("Bye"); + flag = true; + break; + default: + System.out.println("Wrong"); + break; + } + } + System.out.println(Arrays.toString(Information)); + } + static void informationEncoder(String[] information) + { + String NI = Arrays.toString(information.clone()); + System.out.println(NI); + Scanner scanner = new Scanner(System.in); + System.out.println("enter your shift :"); + int shift = scanner.nextInt(); + char[] NI1 = NI.toCharArray(); + for (int i = 0; i < NI1.length ; i++) + { + NI1[i] = (char) (NI1[i] + shift); + } + String NI2 = new String(NI1); + String[] newinformation = NI2.split(","); + System.out.println(Arrays.toString(newinformation)); +// MainPage(newinformation); +// return newinformation; + } + static void informationDecoder(String[] information) + { + String NI = Arrays.toString(information.clone()); + System.out.println(NI); + Scanner scanner = new Scanner(System.in); + System.out.println("enter your shift :"); + int shift = scanner.nextInt(); + char[] NI1 = NI.toCharArray(); + for (int i = 0; i < NI1.length ; i++) + { + NI1[i] = (char) (NI1[i] - shift); + } + String NI2 = new String(NI1); + String[] newinformation = NI2.split(","); + System.out.println(Arrays.toString(newinformation)); +// MainPage(newinformation); +// return newinformation; + } + static String[] userFullInformation() + { + Scanner name = new Scanner(System.in); + System.out.print("enter your firstname : "); + String first = name.nextLine(); + System.out.print("enter your lastname : "); + String last = name.nextLine(); + String FullName = fullName(first,last); + System.out.print("enter your phone number : "); + String phone = name.nextLine(); + String PhoneNumber = phoneNumber(phone); + System.out.print("enter your userid : "); + String user = name.nextLine(); + String ID = UserId(user); + System.out.print("enter your interests : "); + String[] Interest = getInterests(); + String[] UFI = new String[2+Interest.length]; + UFI[0] = "Hello! My name is " + FullName + ". My ID is " + ID + ". Here are some of my interests:"; + for (int i = 1; i < Interest.length+1; i++) + { + UFI[i] = i + ". " + Interest[(i-1)]; + } + UFI[UFI.length-1] = "You can reach me via my phone number " + PhoneNumber + "."; + return UFI; + } + static String[] getInterests() + { + Scanner input = new Scanner(System.in); + String[] List = new String[10]; + int i = 0; + boolean flag = false; + while (flag == false) + { + List[i] = input.nextLine(); + System.out.println("if you done enter (0)"); + if (Objects.equals(List[i], "0")) + { + flag = true; + break; + } + i++; + } + String[] L = new String[i]; + for (int j = 0; j4 && id.length() < 13) + { + flag = false; + } + else + { + System.out.print("Wrong entry.Try again : "); + id = Test.nextLine(); + } + } + return id; + } + static String phoneNumber(String number) + { + Scanner Test = new Scanner(System.in); + String temp = ""; + char[] N = new char[10]; + for (int i = 0; i < number.length(); i++) + { + N[i] = number.charAt(i); + } + boolean flag = true; + while (flag == true) + { + if ((N[0] == '9' && ((number.length() == 10)||(temp.length() == 10)))) + { + flag = false; + } + else + { + System.out.print("Wrong entry.Try again : "); + temp = Test.nextLine(); + for (int i = 0; i < temp.length(); i++) + { + N[i] = temp.charAt(i); + } + } + } + char[] N1 = new char[11]; + N1[0] = '0'; + for (int i = 0,j=1; i < 10; i++,j++) + { + N1[j]=N[i]; + } + return new String(N1); + } + static String fullName(String firstname,String lastname) + { + char[] F = firstname.toCharArray(); + char[] L = lastname.toCharArray(); + if (F[0]>96 && F[0]<123) + { + F[0] = (char) (F[0]-32); + } + if (L[0]>96 && L[0]<123) + { + L[0] = (char) (L[0]-32); + } + for (int i = 1; i < firstname.length(); i++) + { + if (F[i]>96 && F[i]<123) + { + } + else + { + F[i] = (char) (F[i]+32); + } + } + for (int i = 1; i < lastname.length(); i++) + { + if (L[i]>96 && L[i]<123) + { + } + else + { + L[i] = (char) (L[i]+32); + } + } + char[] Full = new char[(firstname.length() + lastname.length() + 1)]; + for (int i = 0; i < firstname.length(); i++) + { + Full[i]=F[i]; + } + Full[firstname.length()]=' '; + int j=0; + for (int i = firstname.length()+1 ; i < firstname.length() + lastname.length() + 1 ; i++) + { + Full[i]=L[j]; + j++; + } + return new String(Full); + } +} \ No newline at end of file