Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; /* * Method validate() takes a password string and determines if it is a valid password * Valid passwords are at least 8

import java.util.Scanner;
/*
* Method validate() takes a password string and determines if it is a valid password
* Valid passwords are at least 8 characters in length and contain at least: one upper case letter,
* one lower case character, one digit, and one of 3 special characters from the set '!' '$' '#'
*/
public class QB4
{
 /*
  * Validate a password string. Returns true if the string is at least 8 characters in length and
  * contains at least: one upper case character, one lower case character, one digit and contains one special
  * character from the set of 3 special characters '!' '$' '#'
  * returns false otherwise
  *
  */
public static boolean validate(String password)
{
 //-----------Start below here. To do: approximate lines of code = 17
 // Fill in the method. Hint: make use of String method charAt(), class Character static methods:
  // isLowerCase(), isUpperCase(), isDigit()
 
 
 //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

public static void main(String[] args)
{
String password = "aBc123xyz!";

 Scanner in = new Scanner(password);
 if (validate(in.next()))
 System.out.println("ok");
 else
 System.out.println("Invalid Password");
 System.out.println("Expected:ok");
 
 password = "aBcxyz";
 in = new Scanner(password);
 if (validate(in.next()))
 System.out.println("ok");
 else
 System.out.println("Invalid Password");
 System.out.println("Expected:Invalid Password");
 
 password = "hello$";
 in = new Scanner(password);
 if (validate(in.next()))
 System.out.println("ok");
 else
 System.out.println("Invalid Password");
 System.out.println("Expected:Invalid Password");
 
 password = "Hello123#";
 in = new Scanner(password);
 if (validate(in.next()))
 System.out.println("ok");
 else
 System.out.println("Invalid Password");
 System.out.println("Expected:ok");

}
}

Include screenshots of the output. 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

import javautilScanner Method validate takes a password string and determines if it is a valid passw... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Basic Statistics

Authors: Charles Henry Brase, Corrinne Pellillo Brase

6th Edition

978-1133525097, 1133525091, 1111827028, 978-1133110316, 1133110312, 978-1111827021

More Books

Students also viewed these Programming questions

Question

Let a 0. Solve |x| = 3.

Answered: 1 week ago