Question: in JAVA Write a program named MapDemo that uses a HashMap to keep track of the users that have access to a companys intranet site.
in JAVA
Write a program named MapDemo that uses a HashMap to keep track of the users that have access to a companys intranet site. The map should include the users ID and password. The program should include the following methods:
- public static void addUser(String userId, String password) the method adds users to a map and displays an appropriate message (see example output).
- public static void displayNumberOfUsers() the method displays the number of users in the map, if the map is empty the following message is displayed: There are currently no users.
- public static void displayUsers() the method displays each users user ID and password on a separate line.
- public static void deleteUser(String userId, String password) the method deletes the user if the user information passed into the method matches a user in the map. If the user has been deleted or not deleted, display an appropriate message (see example output).
- public static void updateUserPassword(String userId, String oldPassword, String newPassword) - the method updates the users password if the user information passed into the method matches a user in the map. If the user has been updated or not updated, display an appropriate message (see example output).
- public static void displayUserPassword(String userId) The method displays the users password if the user ID exists in the map; if the user ID does not exist in the map, display an appropriate message (see example output).
- public static void sortUsers() The method sorts the map in alphabetical order by user ID and displays each users user ID and password on a separate line.
*****The program must include the follow steps:*****
Create an empty HashMap.
Call the displayNumberOfUsers method.
Add the following users to the map by calling the addUser method:
User ID password
dav79684 A82Ty6AGCMqp#
jai88735 !bSWGvFKmd5Ef
adr93442 DqTEcbxX3U3X$
tav36140 &nzK6YFdR74hY
kry52417 rxS5Yf2GeJeZ@
hen22919 #7BV5WMZmUQgp
Call the displayNumberOfUsers method.
Call the displayUsers method.
Attempt to delete the following users by calling the deleteUser method:
- user ID - tav36140 password - &nzK6YFdR74hY
- user ID - hen22919 password - #7BV5WMZmUQg (delete should fail as the passwords do not match)
Add the following users by calling the addUser method:
- user ID - tim15610 password - RhKEsNm5GaYt!
- user ID - ben57543 password - $MyCg7NLg9uCS
Attempt to update the following users passwords by calling the updateUserPassword method:
- user ID - adr93442 old password - DqTEcbxX3U3X$ new password - N7PF4TazRz4N&
- user ID - kry52417 old password - rxS5Yf2GeeZ@ new password - dSPYyNvb9hLH (update should fail as the old password and existing password do not match)
Call the displayUsers method.
Attempt to display the following users passwords by calling the displayUserPassword method:
- tim15610
- tav36140 (the user does not exist)
Call the sortUsers method.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
