Question: *FROM JAVA PROGRAMMING Your job for this problem is to complete the definition of a Password class that can be used to test the safety

*FROM JAVA PROGRAMMING

Your job for this problem is to complete the definition of a Password class that can be used to test the safety level of a give password. We are providing you with a test class named PasswordTest that includes tests and specifications for the different methods that the class must define. You may define additional methods if you like and create any instance variables that you consider necessary. he class must also include a constructor that accepts a String as a parameter and initializes the new instance of the Password class with the given String as the password.

GIVEN CODE FOR CLASS PASSWORD:

import java.util.*;

import java.lang.*;

public class Password {

public static final int STRONG = 10;

public static final int MEDIUM = 5;

public static final int WEAK = 0;

public static final int INVALID = -1;

static Scanner w = new Scanner(System.in);

public static final String pass = w.next();

public Password(String text) {

Password p = new Password(text);

}

public String getText() {

Password g = new Password(pass);

String a = g.toString();

return a;

}

boolean longEnough(int n) {

String l = getText();

if(l.length()

return true;

}

return false;

}

boolean containsOneOf (String chars) {

for(int i=0; i

if(chars.contains("@") || chars.contains("!") || chars.contains("#")

|| chars.contains("^") || chars.contains("&")){

return true;

}

}

return false;

}

boolean containsNoneOf(String chars) {

if(containsOneOf(chars)==false){

return true;

}

return false;

}

boolean containsUpperCase() {

// YOUR CODE

return false;

}

boolean containsLowerCase() {

if (containsUpperCase()==false){

return true;

}

return false;

}

public int safetyLevel() {

String pass = getText();

int level = pass.length();

if(level>=0 && level

}

return level;

}

}

GIVEN PASSWORDTESTER CLASS:

import static org.junit.Assert.*;

import org.junit.Test;

/**

* PasswordTest

* JUnit class designed to test a Password class used to validate the safety levels of passwords

*

*

*/

public class PasswordTest {

@Test

public void testLongEnough() {

// boolean longEnough(n) - returns true iff password has at least n chars

assertTrue("longEnough(n): Incorrect result", new Password("hello").longEnough(5));

assertFalse("longEnough(n): Incorrect result", new Password("hello").longEnough(6));

assertFalse("longEnough(n): Incorrect result", new Password("").longEnough(6));

assertFalse("longEnough(n): Incorrect result", new Password("!@#^&").longEnough(6));

}

@Test

public void testContainsOneOf() {

// boolean containsOneOf(String chars) - returns true iff password contains at least one of the chars in the given String

// special chars, nums and alphabet

assertTrue("containsOneOf: Incorrect result", new Password("Hello World").containsOneOf("abcdefgh"));

assertFalse("containsOneOf: Incorrect result", new Password("Hello World").containsOneOf("123456789"));

assertFalse("containsOneOf: Incorrect result", new Password("Hello World").containsOneOf("!@#$%^&"));

}

@Test

public void testContainsNoneOf() {

// boolean containsNoneOf(String chars) - returns true iff password does not contain any of the chars in the given String

assertTrue("containsNoneOf: Incorrect result", new Password("Hello World").containsNoneOf("123456789_"));

assertFalse("containsNoneOf: Incorrect result", new Password("Hello World").containsNoneOf("1234 56789"));

assertFalse("containsNoneOf: Incorrect result", new Password("Hello World").containsNoneOf("!@#$H%^&"));

}

@Test

public void testContainsUpperCase() {

// boolean containsUpperCase() - returns true iff password contains at least one upper case letter

assertTrue("containsUpperCase: Incorrect result", new Password("Hello World").containsUpperCase());

assertFalse("containsUpperCase: Incorrect result", new Password("").containsUpperCase());

assertFalse("containsUpperCase: Incorrect result", new Password("hello world").containsUpperCase());

}

@Test

public void testContainsLowerCase() {

// boolean containsUpperCase() - returns true iff password contains at least one lower case letter

assertTrue("containsLowerCase: Incorrect result", new Password("Hello World").containsLowerCase());

assertFalse("containsLowerCase: Incorrect result", new Password("").containsLowerCase());

assertFalse("containsLowerCase: Incorrect result", new Password("HELLO WORLD").containsLowerCase());

}

@Test

public void testSafetyLevel() {

// safetyLevel() - Returns:

// Password.STRONG (int 1) if password has at least 10 chars, at least one upper and one lower case letter, at least one digit and at least one of "!@#$%^&*()"

// Password.MEDIUM (int 2) if password has at least 8 chars, at least one upper and one lower case letter, and at least one digit

// Password.WEAK (int 3) if password has at least 8 chars

// Password.INVALID (int 4) if password has less than 8 chars OR at least of of the chars '.' or '/'

assertEquals("safetyLevel: Incorrect result", Password.WEAK, new Password("Hello World").safetyLevel());

assertEquals("safetyLevel: Incorrect result", Password.WEAK, new Password("hello1234").safetyLevel());

assertEquals("safetyLevel: Incorrect result", Password.INVALID, new Password("Qwerty").safetyLevel());

assertEquals("safetyLevel: Incorrect result", Password.INVALID, new Password("Hello/World").safetyLevel());

assertEquals("safetyLevel: Incorrect result", Password.MEDIUM, new Password("HelloWorld1").safetyLevel());

assertEquals("safetyLevel: Incorrect result", Password.MEDIUM, new Password("HelloWorld1").safetyLevel());

assertEquals("safetyLevel: Incorrect result", Password.STRONG, new Password("HelloWorld1!").safetyLevel());

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!