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

This is done in Java. I finished my code. I just need the Demo class. Here is th

ID: 3879181 • Letter: T

Question

This is done in Java. I finished my code. I just need the Demo class.

Here is the question:

Imagine you are developing a software package for Amazon.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 another program that allows the user to enter a password and then displays a message indicating whether it is valid or not.

TIP: You will have two Java programs, one is definition, PasswordVerifier.java for instance, another one is demo, PasswordDemo.java for instance. In your PasswordVerifier.java program you will have to define methods, for example, hasUpperCase(), hasLowerCase(), hasDigit(), and isLongerThenSix() to verify the above mentioned criteria. In your PasswordDemo.java program, you will ask the user to input a password, then call each method defined in PasswordVerifier.java to check if the customer entered password is valid.

Here is my code:

import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author
*/
public class PasswordVerifier {
public static void main(String[] args){
String input; //holds input
boolean hasUpperLetters = false;
boolean hasLowerLetters = false;
boolean hasDigits = false;
boolean hasSomethingElse = false;   
//Creating the Scanner for the keyboard
Scanner keyboard = new Scanner(System.in);
//Get the password
System.out.print("Please enter a password: ");
input = keyboard.nextLine();
int passLength = input.length();
//Loop will repeat for all characters in the string
for (int i=0; i < passLength; i++)
{
char c = input.charAt(i);
//Check for one or moore Upper case letter
if(Character.isUpperCase(c))
hasUpperLetters = true;
//Check for one or more Lower case letter
else if (Character.isLowerCase (c))
hasLowerLetters = true;
//Check for one or more digit
else if (Character.isDigit (c))
hasDigits = true;
else hasSomethingElse = true;
}
//Condition checking for verified password
if (hasUpperLetters && hasDigits && hasLowerLetters && !hasSomethingElse && (passLength >= 6))

{
System.out.println("Your password is formatted correctly");
  
}
else
{
System.out.println("Your password is not formatted correctly");
}
}
}

All I need is the PasswordDemo.java

Thank you.

Explanation / Answer

As per the question provided by you .. PasswordVerifier must not contain the main function but the functions : - hasUpperCase(), hasLowerCase(), hasDigit(), and isLongerThenSix()

and PasswordDemo must contain the main function to get and validate user input.

So your implementation of PasswordVerifier is wrong. Here I am providing the correct implementation.

If you have any trouble understanding or any issue in it , Please comment , I'll resolve the issue

PasswordVerifier.java

public class PasswordVerifier {

// Constant for minimum password length

public static final int MIN_PASSWORD_LENGTH = 6;

/**

* isValid method

*/

public static boolean isValid(String str) {

boolean status; // Validity status

if (isLongerThenSix(str) && hasUpperCase(str) && hasLowerCase(str) && hasDigit(str))

status = true;

else

status = false;

return status;

}

/**

* isLongerThenSix method

*/

private static boolean isLongerThenSix(String str) {

if (str.length() >= MIN_PASSWORD_LENGTH) {

return true;

} else {

return false;

}

}

/**

* hasUpperCase method

*/

private static boolean hasUpperCase(String str) {

boolean status = false; // Validity status

for (int i = 0; i < str.length(); i++) {

if (Character.isUpperCase(str.charAt(i)))

status = true;

}

return status;

}

/**

* hasLowerCase method

*/

private static boolean hasLowerCase(String str) {

boolean status = false; // Validity status

for (int i = 0; i < str.length(); i++) {

if (Character.isLowerCase(str.charAt(i)))

status = true;

}

return status;

}

/**

* hasDigit method

*/

private static boolean hasDigit(String str) {

boolean status = false; // Validity status

for (int i = 0; i < str.length(); i++) {

if (Character.isDigit(str.charAt(i)))

status = true;

}

return status;

}

}

PasswordDemo.java

import java.util.Scanner;

public class PasswordDemo {

public static void main(String[] args) {

String input; // To hold input

// Create a Scanner object for keyboard input.

Scanner keyboard = new Scanner(System.in);

// Get a password.

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

input = keyboard.nextLine();

// Check the password.

if (!PasswordVerifier.isValid(input))

System.out.println("Invalid password.");

else

System.out.println("Valid password.");

}

}

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