1. The User.java (NOTE: this class will not have a main() method) will be used to create objects of the User type, this class should have the following:

a. instance attributes named (NOTE: all of these attributes should be set to private access):

i. id of type long to store the user's unique identification number
ii. password of type String to store the users password
iii. firstName of type String to store the users first name
iv. lastName of type String to store the users last
v. lastAccess of type Date to store the last time the user accessed the system
vi. enrolDate of type Date to store when the user was created in the system
vii. enabled of type boolean to store whether the user is enabled in the system (false would mean the user is disabled)
viii. type of type char to store the users type as a single character

b. for each of the private instance attributes created above, you are to create correctly name getter/accessor and setter/mutator methods. NOTE: you can do this simply in Eclipse by creating the attributes and then selecting Source -> Generate Setters and Getters and accepting the defaults.

c. class attributes named (NOTE: their access type should be public, and they should be set up so that they cannot be change/are constants)

i. DEFAULT_ID of type long that stores 100123456
ii. DEFAULT_PASSWORD of type String that stores "password"
iii. DEFAULT_FIRST_NAME of type String that stores John
iv. DEFAULT_LAST_NAME of type String that stores Doe
v. DEFAULT_ENABLED_STATUS of type boolean that stores true
vi. DEFAULT_TYPE of type char that stores 's'
vii. ID_NUMBER_LENGTH of type byte that stores 9
viii. DF of type DateFormat that formats dates to the DateFormat.MEDIUM for Locale.CANADA

d. constructors (whose access level is public)

i. a parameterized one that accepts arguments, one each for the types corresponding to the attributes listed above, that places each argument into it's appropriate attribute using the setXxx() method
ii. a default one (i.e. one that does not take any arguments), that will set the instance attributes to the public class attributes created above. NOTE: set the enrol date and last access date to today (i.e. the day the program was run). For full marks this default constructor should called the parameterized constructor created above using the this keyword (passing the class attributes and todays date, using new Date() for those two arguments, twice).
iii. a parameterized one that accepts arguments for each of the instance attributes, one each of the types corresponding to the attributes listed above except for the id, the id parameter should take a String (instead of a long primitive) This constructor should be coded to convert the passed String to a long using the Long wrapper class). This constructor should call the parameterized one above using the this keyword

e. Create a instance method (i.e. non-static) named toString() that overloads the java.Object's toString() creates a specific users information as a String in the form:

User Info for: 100123456
Password: ********
Name: John Doe
Created on: 15-Jan-2016
Last access: 15-Jan-2016
Type: s
Enabled: true

To output asterisks instead of the password, place this code when you call the getPassword() method:

getPassword().replaceAll("[ ~!@#$%^&*()_+=-`<>,./?a-zA-Z0-9]", "*")

The first argument of the replaceAll() is a regular expression that will replace all upper- and lower-case letter, numbers and most of the special characters with *.

NOTE: it is not actually changing the password, just the display of it.

f. Create an instance method named displayToConsole() that does not take any arguments, returns nothing and just displays the returned string from the toString() method using System.out.println(toString())

g. Have a class method named verifyId()that accepts a long argument and checks, using ID_NUMBER_LENGTH, whether the string passed is valid (i.e. 9 digits long). This method should return a boolean.

NOTE: for you sre required to use a Wrapper class. Specifically, you should that converts the long stored into a String, and then you can compare the String's length to the class variables acceptable length.

2. Create a Java class named Lab2Tester.java, that has a main method that performs the following:

a. Instantiates four (4) objects of type User. These objects should be passed the following arguments:

i. The first one, named john, is not passed arguments, which means they should use the default class values described above.
ii. The second one, named darren, should be passed the values:

id of “100190125” (NOTE: this calls the constructor that
takes a String as the id argument)
password of "another password"
first name of "Darren"
last name of "Puffer"
type ‘f’ (faculty)
enrol date of December 14 2000
last access date of January 10 2016

iii. The third, named jane, one should be passed the values:

id of 100123
password of "weakpassword"
first name of "Jane"
last name of "Read"
type of ‘s’ (Jane is a student)
enrol date of August 31 2013
last access date of January 14 2016

iv. The fourth one, named after you, should be passed the values that correspond to you as a student (your name, your enroll date, some sort of password etc.)

b. Each object's information should then be display using the displayToConsole() method (have a System.out.println before each display to explain which object you are about to display)

c. Have three (3) System.out.println() that tell whether each of the id numbers is valid or not. Only one will be invalid, Jane Read's.

d. Your program should call at least a couple of the setXxx() methods on jane User object, and call the displayToConsole() method again

Possible OUTPUT:

Instantiating the first default user using the default constructor, and then
displaying it using the displayInfo() method:

User Info for: 100123456
Password: ********
Name: John Doe
Created on: 21-Jan-2016
Last access: 21-Jan-2016
Type: s
Enabled: true

Instantiating the another user for one of my instructors (passing "100190125"
as a String), and then displaying using the displayToConsole() method:

User Info for: 100190125
Password: ****************
Name: Darren Puffer
Created on: 14-Dec-2000
Last access: 10-Jan-2016
Type: f
Enabled: true

Instantiating the another user for a fictional student named Jane, and then
displaying her using the displayToConsole() method:

User Info for: 100123
Password: ************
Name: Jane Read
Created on: 31-Aug-2013
Last access: 14-Jan-2016
Type: s
Enabled: true

Instantiating the another user for myself, and then displaying using the
displayToConsole() method:
User Info for: 100543210
Password: ********
Name: YOUR_FIRST_NAME YOUR_LAST_NAME
Created on: 2-Sep-2014
Last access: 7-Jan-2016
Type: s
Enabled: true

Checking each id number for validity using the verifyId() method:
Using the static User.verifyId() method John's id of 100123456 is valid.
Using the static User.verifyId() method Darren's id of 100190125 is valid.
Using the static User.verifyId() method Jane's id of 100123 is not valid.
Using the static User.verifyId() method YOUR_FIRST_NAME's id of 100543210 is
valid.

After changing her last name, her password, the last access and disabling her
using various setXxx() methods, the Jane object now displays:

User Info for: 100123
Password: *******
Name: Jane Smith
Created on: 31-Aug-2013
Last access: 20-Jan-2016
Type: s
Enabled: false
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.