Question

In: Computer Science

Write a Java program (name it PasswordTest) that reads from the user a string input (representing...

Write a Java program (name it PasswordTest) that reads from the user a string input (representing a password) and determines whether the password is “Valid Password” or “Invalid Password”. A valid password has at least 7 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, CS5000/01 is invalid password; however, Cs5000/01 is a valid password. The program should display the entered password and the judgment as shown in the following sample runs:

Entered Password: CS5000/01

Verdict: Invalid Password

Entered Password: Cs5000/011

Verdict: Valid Password

Entered Password: MyOldDogK9

Verdict: Invalid Password

Entered Password: MyOldDogK9#

Verdict: Valid Password

Entered Password: Ab1#

Verdict: Invalid Password

Document your code, and organize and space out your outputs as shown. Design your program such that it allows the user to re-run the program with different inputs in the same run (i.e., use a sentinel loop structure).

Solutions

Expert Solution

Thanks for the question.


Below is the code you will be needing  Let me know if you have any doubts or if you need anything to change.


Thank You !!


===========================================================================

import java.util.Scanner;

public class PasswordValidator {


    public static boolean validPassword(String password) {


        if (password == null) return false;
        int length = 0;
        boolean containLowerCase = false;
        boolean containsUpperCase = false;
        boolean containsDigit = false;
        boolean containsSpecialCharacter = false;

        for (int i = 0; i < password.length(); i++) {
            length += 1;
            char letter = password.charAt(i);
            if ('a' <= letter && length <= 'z') containLowerCase = true;
            else if ('A' <= letter && length <= 'Z') containsUpperCase = true;
            else if ('0' <= letter && letter <= '9') containsDigit = true;
            else containsSpecialCharacter = true;
        }

        return length >= 7 && containLowerCase && containsUpperCase &&
                containsDigit && containsSpecialCharacter;
    }

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter Password: ");
        String password = scanner.nextLine();
        if (PasswordValidator.validPassword(password)) {
            System.out.println("Verdict: Valid Password");
        } else {
            System.out.println("Verdict: Invalid Password");
        }
    }
}


Related Solutions

in. java Write a program that reads a string from the user, and creates another string...
in. java Write a program that reads a string from the user, and creates another string with the letters from in reversed order. You should do this using string concatenation and loops. Do not use any method from Java that does the work for you. The reverse string must be built. Do not just print the letters in reversed order. Instead, concatenate them in a string. --- Sample run: This program will create a string with letters in reversed order....
Write a JAVA program that reads in a string from standard input and determines the following:...
Write a JAVA program that reads in a string from standard input and determines the following: - How many vowels are in the string (FOR THE PURPOSE OF THIS PROGRAM 'Y' is NOT considered a vowel)? - How many upper case characters are in the string? - How many digits are in the string? - How many white space characters are in the string? - Modify the program to indicate which vowel occurs the most. In the case of a...
Write a C++ or Java program that reads an input graph data from a user. Then,...
Write a C++ or Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number ofvertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2...
Write a Java program that reads an input graph data from a user. Then, it should...
Write a Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number of vertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2 0...
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
Write a Java program (name it LargestOccurenceCount) that reads from the user positive non-zero integer values,...
Write a Java program (name it LargestOccurenceCount) that reads from the user positive non-zero integer values, finds the largest value, and counts it occurrences. Assume that the input ends with number 0 (as sentinel value to stop the sentinel loop). The program should ignore any negative input and should continue to run. Hint: to remember/save entered (good) values, you can concatenate them into a string (separated by spaces) that you can output later on. Sample runs showing input prompts and...
Write a Java program that uses printf, and takes user input to find the name of...
Write a Java program that uses printf, and takes user input to find the name of the File. FileCompare (20) Write a program that compares to files line by line, and counts the number of lines that are different. You can use file1.txt and file2.txt when testing your program, but you must ask for the file names in the input. main Interactively requests the names of the two files, after creating the Scanner for the keyboard. Creates a Scanner for...
Write a program that reads three values from the keyboard representing, respectively, an investors name, an...
Write a program that reads three values from the keyboard representing, respectively, an investors name, an investment amount, and an interest rate (you will expect the user to enter a number such as .065 for the interest rate, representing a 6.5% interest rate) . Your program should calculate and output (in currency notation) the future value of the investment in 10, 2 20 an 30 years using the following formula:   Future value =investment(1+interest rate)year Example of a test run: Enter...
Write a program that takes a string input from the user and then outputs the first...
Write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word. After going up to the full word, go back down to a single letter. LastNameUpDown. Input: Kean Output: K Ke Kea Kean Kea Ke K
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT