Skip to content

Functions-Introduction project files #44

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 8 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/40230112115/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
root = true

[*]
29 changes: 29 additions & 0 deletions Answers/40230112115/.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
3 changes: 3 additions & 0 deletions Answers/40230112115/.idea/.gitignore

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

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

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

149 changes: 149 additions & 0 deletions Answers/40230112115/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import java.util.Scanner;

import static java.lang.String.valueOf;

public class Main
{
public static void main(String[] args) {
Scanner stringInput = new Scanner(System.in);
}
public static String fullName(String firstName,String lastName)
{
Scanner input = new Scanner(System.in);
firstName = input.next();
lastName = input.next();
firstName = firstName.toLowerCase();
lastName = lastName.toLowerCase();
String fullname = "";
char firsta[] = firstName.toCharArray();
char lasta[] = lastName.toCharArray();
firsta[0] -= 32;
lasta[0] -= 32;
int n1 = firsta.length;
int n2 = lasta.length;
char fulla[] = new char[n1 + n2 + 1];
for (int i = 0; i < n1; i++) {
fulla[i] = firsta[i];
}
fulla[n1] = ' ';
for (int i = 0; i < n2; i++) {
fulla[i + n1 + 1] = lasta[i];
}
fullname=valueOf(fulla);
return fullname;
}


public static String phoneNumber(String phone)
{
Scanner input = new Scanner(System.in);
phone = input.next();
char[] phoneArray = phone.toCharArray();
String newPhone="0";
int n=phone.length();
while (n!=10 || phoneArray[0]!='9') {
System.out.println("Worng entry. Try again");
phone = input.next();
n=phone.length();
phoneArray = phone.toCharArray();
}
newPhone+=phone;
return newPhone;
}

public static String userId(String id)
{
Scanner input = new Scanner(System.in);
int n=0;
while (n>13 || n<4) {
id = input.next();
n=id.length();
if(id.length()>13 || id.length()<4) {
System.out.println("Worng ID. Try again");
}
}
return id;
// }

public static String getInterests(String interest)
{
Scanner input = new Scanner(System.in);
int i=0;
interest="";
String x="{";
while(i<10){
interest = input.nextLine();
if(interest.length()!=0){
x= x+ "\"" + interest+ "\",";
}else{
break;
}
i++;
}
if(x.length()!=1) {
x = x.substring(0, x.length() - 1) + "}";
}else{
x="{}";
}
return x;
}

public static String userFullInformation(String fullName, String phoneNumber, String userID,String interests)

{
Scanner input = new Scanner(System.in);
fullName = input.nextLine().trim();
phoneNumber = input.nextLine();
userID = input.nextLine();
interests = input.nextLine();
interests=interests.replace("}","").replace("{","").replace(" ","").replace("\"","");
String[] interestsArray = interests.split(",");
String output="Hello! My name is " + fullName + ". My ID is "+ userID + ". Here are some of my interests:";
for(int i=0;i<interestsArray.length;i++){
output=output + "\n" + (i+1) +"." +interestsArray[i];
}
output=output+"\n\n"+"You can reach me via my phone number "+phoneNumber+".";
return output;
}

public static String informationEncoder(String information, String shift)
{
Scanner input = new Scanner(System.in);
information = input.nextLine();
shift = input.nextLine();
int x=Integer.parseInt(shift);
char[] info= information.toCharArray();
int n=info.length;
for(int i=0 ; i<n ; i++){
if((info[i]<91 && info[i]>64 && (info[i]+x)>90)||(info[i]<123 && info[i]>96 && (info[i]+x)>122)){
info[i]+=x;
info[i]-=26;
}else if((info[i]<91 && info[i]>64)||(info[i]<123 && info[i]>96)){
info[i]+=x;
}
}
String y= new String(info);
return y;
}

public static String informationDecoder(String information, String shift)
{
Scanner input = new Scanner(System.in);
information = input.nextLine();
shift = input.nextLine();
int x=Integer.parseInt(shift);
char[] info= information.toCharArray();
int n=info.length;
for(int i=0 ; i<n ; i++){
if((info[i]<91 && info[i]>64 && (info[i]-x)<65)||(info[i]<123 && info[i]>96 && (info[i]-x)<97)){
info[i]-=x;
info[i]+=26;
}else if((info[i]<91 && info[i]>64)||(info[i]<123 && info[i]>96)){
info[i]-=x;
}
}
String y= new String(info);
return y;
}

}
11 changes: 11 additions & 0 deletions Answers/40230112115/untitled3.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>