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

Java Program Needed Please pay extra attention to bold items below: . -use Java

ID: 3859279 • Letter: J

Question

Java Program Needed

Please pay extra attention to bold items below:

.

-use Java (I will check the working code in Eclipse one answer is provided)

-Everthing must be done under main methods meaning do not create extra methods in the code.

-use WHILE LOOP and BOOLEAN(True/False) in the program so that way the program should stop only when the user enters a valid password.

-must use Character.isLetterOrDigit(ch) to check if ch is letter or digit. example would be Character.isDigit(ch)

.

Suppose a website impose the following rules for passwords.

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. If the user enters an invalid password, the program needs to tell the user why it is invalid and ask the user to enter another password. The program should stop only when the user enters a valid password.

Use this sample run to check these 4 passwords in order(Please run this sample run, program should only exit once a "VALID PASSWORD" is typed. it will not exit otherwise. valid passoword in this case is Mypassword18 as shown below.

-

Enter a new password: My password18

Invalid: Only letters and digits

Enter a new password: pass18

Invalid: Too Few Characters (8 at least)

Enter a new password: password

Invalid: At least two digits

Enter a new password: Mypassword18

Valid password!

.

NOTE:

add the while loop to handle potentially multiple passwords so that the program will stop only when a valid password is typed.

For a password that violates multiple rules, you only need to let the user know the first rule that is violated.

Explanation / Answer

//simple password program
import java.util.Scanner;
public class PasswordTest
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
String password;
String verdict = "Invalid";
  
while (verdict == "Invalid")
{//Loop runs until a valid password is input
System.out.print("Enter Password: ");
password = s.nextLine();
  
boolean is8 = password.length() >= 8;
boolean hasUppercase = !password.equals(password.toLowerCase());
boolean hasLowercase = !password.equals(password.toUpperCase());
  
if (is8 && hasUppercase && hasLowercase)
verdict = "Valid";
  
System.out.println("Entered Password: " + password);
System.out.println("Verdict: " + verdict);   
}
}
}
-------------

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