You are on page 1of 2

Assignment (10 Marks) EKT 243: Object Oriented Programming (C5, CO3, PO2)

You are required to write a complete Java code for class PasswordStorage class. Details of
PasswordStorage class as shown in Figure 1. In all cases, special characters should be limited
to '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_' and '-' character only.

Constructor
PasswordStorage (String userName, String password, String URL)
Construct new PasswordStorage with provided user name, password and URL.
PasswordStorage (String userName, String URL)
Construct new PasswordStorage with provided user name and URL. Password should be generated
automatically. Password should consists of exactly 12 characters, has AT LEAST ONE digit, ONE
lower case alphabet, ONE upper case alphabet and ONE special character

Method Summary
Modifier and Method and Description
Return Type
String getUserName()
return current user name.
String getPassword()
return current password.
String getURL()
return current URL.
void setNewUserName(String newUserName)
set user name to newUserName
void setNewPassword(String newPassword)
set password to newPassword
void setNewPassword(int passwordLength)
set password to randomly create password consists of paswordLength
characters (minimum 8 characters password). The created password also need
to include AT LEAST ONE digit, ONE lower case alphabet, ONE upper case
alphabet and ONE special character
void setNewURL(String newURL)
set URL to newURL.
static String generateRandomPassword(int length, boolean containDigit, boolean
containUpper, boolean containLower, boolean containSpecial)
return a randomly created password with length number of characters. However,
minimum password length must be 8 characters. The created password should:-
i. contain at least one digit if containDigit is True,
ii. contain at least one upper case alphabet if containUpper is True,
iii. contain at lease one lower case alphabet if containLower is True and
iv. contain at least on special character if containSpecial is True.
static String passwordStrength(String password )
return the strength of the password. The strength of the password is determine
based on point system and as follows:
i. password is “Weak” if total point is less than 5
ii. password is “OK” if total point is between 5 and 6
iii. password is “Good” if total point is 7 and 8
iv. password is “Strong” if total point is more than 9

Point is awarded using following rules:-


i. 2 points is awarded if password length is more than and equal to 10
character, 1 point if the password length is between 8 and 9 characters
and no point if password length is less than 8 characters.
ii. 2 points is awarded if password contains at least one digit
iii. 2 points is awarded if password contains at least one upper case
alphabet
iv. 2 points is awarded if password contains at least one lower case
alphabet
v. 2 points is awarded if password contains at least one special character.

String toString()
an overriden method that return String representation of the object. Given the
following code:-

PasswordStorage ps = new PasswordStorage("rozmie",


"www.unimap.edu.my");
System.out.println(ps);

The output is:-

User name: rozmie


Password: 63y^14@ZYE3D
URL: www.unimap.edu.my
Password Strength: Strong

It should be noted that, you can have as many private instances and methods as you want.

You might also like