Skip to content

functions-introduction done #29

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 10 commits 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
3 changes: 3 additions & 0 deletions Answers/.idea/.gitignore

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

1 change: 1 addition & 0 deletions Answers/.idea/.name

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

1 change: 1 addition & 0 deletions Answers/.idea/description.html

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

9 changes: 9 additions & 0 deletions Answers/.idea/misc.xml

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

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

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

3 changes: 3 additions & 0 deletions Answers/.idea/project-template.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/.idea/vcs.xml

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

Binary file not shown.
203 changes: 203 additions & 0 deletions Answers/src/com/company/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
package com.company;

import java.util.Arrays;
import java.util.Objects;
import java.util.Scanner;

public class Main {

static String fullNameStatic = "";
static String phoneNumberStatic = "";
static String idStatic = "";
static int lenStatic;
static String[] finalInterestsStatic = new String[10];

public static String fullName(){
System.out.println("enter your name : ");
Scanner input = new Scanner(System.in);
String firstname = input.nextLine();
System.out.println("enter your lastname : ");
String lastname = input.nextLine();
char[] firstNameChar = firstname.toCharArray();
char[] lastNameChar = lastname.toCharArray();

for (int i = 0 ; i < firstNameChar.length ; i++){
if (firstNameChar[i] >= 'A' && firstNameChar[i] <= 'Z'){
firstNameChar[i]= (char) (firstNameChar[i]+32);
}

}
firstNameChar[0]= (char) (firstNameChar[0]-32);

for (int i = 0 ; i < lastNameChar.length ; i++){
if (lastNameChar[i] >= 'A' && lastNameChar[i] <= 'Z'){
lastNameChar[i]= (char) (lastNameChar[i]+32);
}

}
lastNameChar[0]= (char) (lastNameChar[0]-32);

fullNameStatic = String.valueOf(firstNameChar) + " " + String.valueOf(lastNameChar);
return fullNameStatic;

}

public static String phoneNumber(){

boolean condition = true;

while (condition){
Scanner input = new Scanner(System.in);
String phoneNumber = input.nextLine();
char[] phoneNumberChar = phoneNumber.toCharArray();
if (phoneNumberChar[0] == '9' && phoneNumberChar.length == 10){
phoneNumberStatic = "0" + String.valueOf(phoneNumberChar);
return "0" + String.valueOf(phoneNumberChar);
} else
System.out.println("Wrong entry. Try again.");
}

return null;
}

public static String userId(){

Scanner input = new Scanner(System.in);
while (true){
String id = input.nextLine();
char[] idChar = id.toCharArray();
if ( idChar.length <= 13 && idChar.length >= 3){
idStatic = String.valueOf(idChar);
return String.valueOf(idChar);
} else
System.out.println("Wrong entry. Try again.");
}

}

public static String[] getInterests(){

String[] interests = new String[10];
Scanner input = new Scanner(System.in);
int len = 0;
for (int i = 0 ; i < 10 ; i++){
String interest = input.nextLine();
if (Objects.equals(interest, "end")){
break;
}
interests[i]=interest;
len++;
}
lenStatic = len;
String[] finalInterests = new String[len];
for (int i = 0 ; i < len ; i++){
finalInterests[i] = interests[i];
}

for (int i = 0 ; i < len ; i++){
finalInterestsStatic[i] = finalInterests[i];

}

return finalInterests;
}

public static String userFullInformation(){
String s1 = "Hello! My name is " + fullNameStatic + ".My ID is " + idStatic + ". Here are some of my interests:";
String s2 = "";
for (int i = 0 ; i < lenStatic ; i++){
s2 = s2 + "\n";
s2 = s2 + (i+1) + ". " + finalInterestsStatic[i] ;
}
String s3 = "You can reach me via my phone number " + phoneNumberStatic;
return s1 + s2 + "\n" + s3;
}

public static String informationEncoder (String userInfo, int shift) {
char[] informationChar = userInfo.toCharArray();

for (int i = 0; i < informationChar.length; i++){
char currentChar = informationChar[i];

if (Character.isLetter(currentChar)) {
char shifting;
if (Character.isLowerCase(currentChar)) {
shifting = 'a';
} else { shifting = 'A';}

informationChar[i] = (char) ((currentChar - shifting + shift)%26 + shifting);

}
}

return String.valueOf(informationChar);
}

public static void informationDecoder(String userInfo, int shift) {
char[] informationChar = userInfo.toCharArray();

for (int i = 0; i < informationChar.length; i++) {
char currentChar = informationChar[i];

if (Character.isLetter(currentChar)) {
char shifting;
if (Character.isLowerCase(currentChar)) {
shifting = 'a';
} else { shifting = 'A';}
int decoded = currentChar - shift - shifting;
if (decoded < 0) {
decoded+= 26;
}
informationChar[i] = (char) (decoded + shifting);
}
}

System.out.println(String.valueOf(informationChar));
}

public static void main(String[] args) {

//first function
System.out.println("Full name : " + fullName());

//second function
System.out.println("enter your phone number : ");
System.out.println("phone number : " + phoneNumber());

//third function
System.out.println("enter your ID : ");
System.out.println("ID : " + userId());

//fourth function
System.out.println("enter your interests : ");
System.out.println("the maximum number of interests is 10.");
System.out.println("if you want to enter less than 10 interests, you have to enter \"end\" when you are finished.");
System.out.println(Arrays.toString(getInterests()));

//fifth function
//System.out.println(userFullInformation());
String userInfo = userFullInformation();

//sixth and seventh function
System.out.println("if you want to see the encoded version of your info please enter \"encode\" , if you don't want to enter \"info\".");
Scanner input = new Scanner(System.in);
String entry = input.nextLine();

if (Objects.equals(entry, "encode")){
System.out.println("enter the amount of shift : ");
int shift = input.nextInt();
System.out.println(informationEncoder(userInfo , shift));
System.out.println("if you want to see the decoded version enter \"decode\" and if you don't want to, enter anything :)." );
Scanner input2 = new Scanner(System.in);
String entry2 = input2.nextLine();
if (Objects.equals(entry2, "decode")){
String userInfo2 = informationEncoder(userInfo , shift);
informationDecoder(userInfo2, shift);
}
}
if (Objects.equals(entry, "info")){
System.out.println(userFullInformation());
}

}
}
12 changes: 12 additions & 0 deletions Answers/untitled104.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?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>