Answer to Question #256349 in Java | JSP | JSF for I AM IRONMAN

Question #256349
Write a general error handling class that has general functions that would take in a username and has the following conditions: Any sort of input from the user where we would expect them to make a mistake • the user can not enter numbers into their user name in username otherwise it would return an error • the user must enter atleast one cap character in the text field if not it returns an error • the user cannot enter special characters in the user name otherwise it would return invalid login.
1
Expert's answer
2021-10-25T16:55:27-0400
import java.util.Scanner;
public class Main
{
 public static void main(String[] args) {
    Scanner in=new Scanner(System.in);
    String special_char = "~`!@#$%^&*()-_=+\\|[{]};:'\",<.>/?";
    char CC;
    boolean numP = false;
    boolean upper = false;
    boolean lower = false;
    boolean special = false;
    System.out.print("Enter a string: ");
    String input=in.next();
    for (int i = 0; i < input.length(); i++) {
        CC = input.charAt(i);
        if (Character.isDigit(CC)) {
            numP = true;
        } 
        else if (Character.isUpperCase(CC)) {
            upper = true;
        } 
        else if (Character.isLowerCase(CC)) {
            lower = true;
        } 
        else if (special_char.contains(String.valueOf(CC))) {
            special = true;
        }
        else{
            System.out.print("Invalid login");
        }
    }
    System.out.print("Valid login");
}
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS