Write the Java source code necessary to build a solution for

Write the Java source code necessary to build a solution for EITHER of the following problem:

Program A

(Check password) Some websites impose certain rules for passwords. Write a method that checks whether a string is a valid password. Suppose the password rules are as follows:

A password must have at least eight characters.

A password consists of only letters and digits.

A password must contain at least two digits.

Write a program that prompts the user to enter a password and displays Valid Password if the rules are followed or Invalid Password otherwise.

Program B

(Count the letters in a string ) Write a method that counts the number of letters in a string using the following header:
public static int countLetters(String s)
Write a test program that prompts the user to enter a string and displays the number of letters in the string , not counting numbers, spaces, or symbols.

Solution

Program A:

import java.util.Scanner;
class PasswordValidity
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);

boolean size;
boolean special;
boolean digit;
int count = 0;

System.out.println(\"Enter password:\");
String password = scanner.nextLine();

size = false;
special = false;
digit = false;
int length = password.length();
count=0;
int digitLen=0;
while (count < length) {
char ch = password.charAt(count);

if (length >= 8) {
size = true;
}

if (!Character.isLetterOrDigit(ch)) {
special = true;
}
if (Character.isDigit(ch)) {
digitLen++;
digit = true;
}
count++;
}
if (size && !special && digit && digitLen>=2) {
System.out.println(\" Valid Password\");
} else {
System.out.println(\"Invalid Password\");
}

}
}

Program B:

import java.util.Scanner;
class LetterCount
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);

//String str;

System.out.println(\"Enter String:\");
String str= scanner.nextLine();

int res=countLetters(str);
System.out.println(\"Count: \"+res);
}

public static int countLetters(String s)
{
   int length=s.length();
   int count=0,c=0;

   while(count<length)
   {
       char ch=s.charAt(count);
       if (Character.isLetter(ch)) {
           c++;
       }
       count++;
   }
   return c;
}
}

Write the Java source code necessary to build a solution for EITHER of the following problem: Program A (Check password) Some websites impose certain rules for
Write the Java source code necessary to build a solution for EITHER of the following problem: Program A (Check password) Some websites impose certain rules for

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site