Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design and implement a Java program that accepts a string from the user and eval

ID: 3758104 • Letter: D

Question

Design and implement a Java program that accepts a string from the user and evaluates it as a password, giving it a valid or invalid verdict. A good password will be at least 8 characters and includes at least one lower-case letter, at least one upper-case letter, at least one digit, and at least one character that is neither a letter nor a digit. Your program will need to check each character in the string in order to render a verdict. For example, CS2301/05 is invalid password. The program should display the entered password and the program’s Judgment on it. For example, Entered Password: CS2301/05 Verdict: Invalid

Explanation / Answer

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class PasswordStrength
{
   public static void main (String[] args) throws java.lang.Exception
   {
       // your code goes here
       Scanner input = new Scanner(System.in);
       String password = input.nextLine();
      
       char temp;
       int ascii;
      
       int lower = 0,upper = 0,digit = 0,other = 0;
      
       int len = password.length();
      
       if(len>=8)
       {
           for(int i=0;i<len;i++)
           {
               temp = password.charAt(i);
               ascii = (int)temp;
               if(ascii>=65 && ascii<=90)
                   upper = upper+1;
               else if (ascii>=97 && ascii<=122)
                   lower = lower+1;
               else if(ascii>=48 && ascii<=57)
                   digit = digit+1;
               else
                   other = other+1;
           }
       }
      
       if(lower!=0 && upper!=0 && digit!=0 && other!=0)
           System.out.println("Verdict : Valid");
       else
           System.out.println("Verdict : Invalid");
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote