Skip to content

Instantly share code, notes, and snippets.

@feehe21
Created November 30, 2018 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feehe21/38ce7f97b094478c23e5c94001410c2f to your computer and use it in GitHub Desktop.
Save feehe21/38ce7f97b094478c23e5c94001410c2f to your computer and use it in GitHub Desktop.
import java.util.*;
/**
* Write a description of class strings here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class strings
{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
System.out.println("Write your FULL name");
String fullName = scan.nextLine();
System.out.println("Write your 4 digit graduation year");
String gradYear = scan.nextLine();
int firstSpace = fullName.indexOf(" ");
String firstName = fullName.substring(0,(firstSpace));
String restOfName = fullName.substring(firstSpace + 1);
int secondSpace = restOfName.indexOf(" ");
//System.out.println("second space = " + secondSpace);
int NamesNum = 0;
String lastName;
String middleName = "";
String username = "";
//System.out.println(firstName);
if(secondSpace == -1){
NamesNum = 2;
lastName = restOfName;
//System.out.println("1 space");
}
else{
NamesNum = 3;
//System.out.println(fullName.length());
middleName = restOfName.substring(0,secondSpace);
lastName = restOfName.substring(secondSpace+1);
//System.out.println("2 spaces");
}
gradYear = gradYear.substring(2);
//System.out.println(firstName);
//System.out.println(middleName);
//System.out.println(lastName);
if(middleName.length() > 0 && lastName.length() > 3){
username = lastName.substring(0,4) + firstName.substring(0,1) + middleName.substring(0,1) + gradYear;
}else if(lastName.length() > 3){
username = lastName.substring(0,4) + firstName.substring(0,1) + gradYear;
}else if(middleName.length() > 0){
username = lastName + firstName.substring(0,1) + middleName.substring(0,1) + gradYear;
}else{
username = lastName + firstName.substring(0,1) + gradYear;
}
System.out.println(username);
System.out.println("If you would like a password too, type 0");
int x = scan.nextInt();
if(x == 0){
String letters = "abcdefghijklmnopqrstuvwxyz";
String numbers = "0123456789";
String spec = "!@#$%^&*?";
int count = 0;
int pick;
int rand;
String password = "Password: ";
int lettersUsed = 0;
int numbersUsed = 0;
int specUsed = 0;
int upperUsed = 0;
while (count < 8){
//(int)(Math.random() * ((max-min) + 1)) + min;
pick = (int)(Math.random()*(3+1));
if(pick == 0){
lettersUsed++;
rand = (int)(Math.random() * ((letters.length()-1-1) + 1)) + 1;
password = password + letters.substring(rand-1, rand);
}else if(pick == 1){
numbersUsed ++;
rand = (int)(Math.random() * ((numbers.length()-1-1) + 1)) + 1;
password = password + numbers.substring(rand-1, rand);
}else if(pick == 2){
specUsed ++;
rand = (int)(Math.random() * ((spec.length()-1-1) + 1)) + 1;
password = password + spec.substring(rand-1, rand);
}else{
upperUsed ++;
rand = (int)(Math.random() * ((letters.length()-1-1) + 1)) + 1;
password = password + (letters.substring(rand-1, rand)).toUpperCase();
}
count++;
}
System.out.println(password);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment