Created
November 30, 2018 22:51
-
-
Save feehe21/38ce7f97b094478c23e5c94001410c2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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