import java.util.Scanner;
public class midquiz {
// Variables
private static String name;
private static String passInput;
private static String ans;
private static CharSequence userPass="PasswOrd";
private static int length;
private static int passLength;
private static int upperVowel = 0;
private static int upperConsonant = 0;
private static int lowerVowel = 0;
private static int lowerConsonant = 0;
public static void main (String [] args) {
Scanner input = new Scanner(System.in);
// Prompt for username
System.out.print("Enter Username: ");
name = input.nextLine();
length = name.length();
// Check appropriate length
if (length < 8 || length > 15) {
System.out.print("Username must be between 8 and 15 characters in length.");
return;
} else;
// If name appropriate, then continue
// Prompt for password
System.out.print("Enter Password: ");
passInput = input.nextLine();
// Verify password
if (passInput.contentEquals(userPass)) {
System.out.println("Password valid.");
// If password is correct:
for (;;) {
passLength = passInput.length();
upperVowel = 0;
upperConsonant = 0;
lowerVowel = 0;
lowerConsonant = 0;
// Count the number of uppercase and number of lowercase consonants and vowels.
for (int i = 0; i < passLength; ++i) {
Character letter = new Character(passInput.charAt(i));
boolean isUpperCase = Character.isUpperCase(letter);
boolean isLowerCase = Character.isLowerCase(letter);
if (isUpperCase == true) {
// Identifying vowels
if ( letter.equals('A') || letter.equals('E') ||
letter.equals('I') || letter.equals('O') ||
letter.equals('U')) {
// If it's a vowel then increase capitalized vowel count
++upperVowel;
// ...otherwise, increase capitalized consonant count
} else {
++upperConsonant;
}
} else if (isLowerCase == true){
// Identifying vowels
if (letter == 'a' || letter == 'e' ||
letter == 'i' || letter == 'o' ||
letter == 'u' ) {
// If it's a vowel then increase lowercase vowel count
++lowerVowel;
// ...otherwise, increase lowercase consonant count
} else {
++lowerConsonant;
}
} else {
// If you wanted to count digits as well, you could add that here.
}
}
System.out.println("There are " +upperVowel+ " uppercase vowels.");
System.out.println("There are " +upperConsonant+ " uppercase consonants.");
System.out.println("There are " +lowerVowel+ " lowercase vowels.");
System.out.println("There are " +lowerConsonant+ " lowercase consonants.");
System.out.println("Try again (Re-count)? [Yes/No]: ");
ans = input.nextLine();
if (ans.equalsIgnoreCase("no")) {
System.exit(0);
}
else if (ans.equalsIgnoreCase("yes")) {
} else {
System.out.println("Invalid choice. Try again?");
}
}
}
else;
// If password is incorrect:
System.out.println("Invalid password.");
System.out.println("Try Again? [Yes/No]:");
ans=input.nextLine();
// If no
if (ans.equalsIgnoreCase("no")) {
System.exit(0);
}
else;
// Whatever you want it to do.
}
}