Answer to Question #256335 in Java | JSP | JSF for VIJAY

Question #256335
Write a general error handling class that has general functions that would take in a string, which the main pages would get as an input and those functions can search for specific things. For example: 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 user login otherwise it would return an error • where 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 an error.
1
Expert's answer
2021-10-25T16:55:40-0400
import java.util.Scanner;
public class Main
{
 public static void main(String[] args) {
 String special = "~`!@#$%^&*()-_=+\\|[{]};:'\",<.>/?";
 char ch;
 boolean n = false;
 boolean upperCharacter = false;
 boolean lowerCharacter  = false;
 boolean specialLetter = false;
 System.out.print("Enter a string: ");
 Scanner scan  = new Scanner(System.in);
 String input = scan.nextLine();
 for (int i = 0; i < input.length(); i++) {
 ch = input.charAt(i);
 if (Character.isDigit(ch)) {
 n = true;
 } else if (Character.isUpperCase(ch)) {
 upperCharacter  = true;
 } else if (Character.isLowerCase(ch)) {
 lowerCharacter  = true;
 } else if (special.contains(String.valueOf(ch))) {
 specialLetter = true;
 }
 else{
 System.out.print("Invalid Credentials");
 }
 }




 return
 n && upperCharacter  && lowerCharacter  && specialLetter;
}}
}

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