Write a class that verifies that a password meets the


This is the problem:

Imagine you are developing a software package for Ama/tHi.com that requires users to enter their own passwords.

Your software requires that users' passwords meet the following criteria:

• The password should be at least six characters long.

• The password should contain at least one uppercase and at least one lowercase letter.

• The password should have at least one digit.

Write a class that verifies that a password meets the stated criteria. Demonstrate the class in a program that allows the user to enter a password and then displays a message indicating whether it is valid or not.

I wrote the program as follows:

import java.util.Scanner;

public class Password { public static void main(String [] args)

{ String input; boolean hasUpperLetters = false;

boolean hasLowerLetters = false;

boolean hasDigits = false;

boolean hasSomethingElse = false;

Scanner keyboard = new Scanner(System.in);

System.out.print("Enter a password: ");

input = keyboard.nextLine();

int passLength = input.length();

for (int i=0; i< passLength; i++) {

char c = input.charAt(i);

if (Character.isUpperCase(c))

hasUpperLetters= true;

else if (Character.isLowerCase(c))

hasLowerLetters=true;

else if (Character.isDigit (c))

hasDigits = true;

else hasSomethingElse = true; }

if (hasUpperLetters && hasDigits && hasLowerLetters && !hasSomethingElse && (passLength >=6)) {

System.out.println("Password is correctly formatted"); }

else { System.out.println("Password is not correctly formatted");

}

}

}

The algorithm is correct and runs correctly, BUT, our teacher wants us to have methods in the program, methods that "returns" values, so that the program is more efficient.

Can someone help me please?

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Write a class that verifies that a password meets the
Reference No:- TGS02898497

Expected delivery within 24 Hours