Skip to content

final project #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added Answers/.DS_Store
Binary file not shown.
29 changes: 29 additions & 0 deletions Answers/40230112089/.gitignore
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions Answers/40230112089/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Answers/40230112089/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Answers/40230112089/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions Answers/40230112089/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Answers/40230112089/Tamrin2.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
115 changes: 115 additions & 0 deletions Answers/40230112089/src/Functions.java
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> 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();
}
}

128 changes: 128 additions & 0 deletions Answers/40230112089/src/Main.java
Original file line number Diff line number Diff line change
@@ -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<String> 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);
}
}


}


}