Java代写:CSCI2110 Review of Hashing

练习数据结构中Hashmap的使用方法,编写一个login小程序。

Review of hashing (from the lectures)

Study the two exercises discussed in the lectures. Download the source codes and the students.txt file (links given next to Lab 9 link).

HashMapDemo.java

Run the above with students.txt

HashMapDemo1.java

Run the above with a sample set of words, one word on each line, ending with “end”
Then complete the following exercise.

Exercise

Your friend is starting up a new web site that is going to have users register as members. He asks you to help implement an application that would validate a member’s login.
Your task is to write a program that reads a file containing the full name, username, and password for each user.
Create a hashmap with the username as key and the password as value. Create another hashmap with the username as key and full name as value.
After the file is read, prompt the user to enter the login name and password. If the password is incorrect, give the user two more chances. If the password is incorrect all three times, the program quits. If the login is successful, print a welcome message. Use the first hashmap to check the username and password match, and use the second hashmap to print the welcome message.
Here’s a sample input file:

Ichabod Crane      icrane       qwerty123
Brom Bones         bbones       pass456!
Emboar Pokemon     epokemon     password123
Rayquazza Pokemon  rpokemon     drow456
Cool Dude          cdude        gh456!32
Trend Chaser       tchaser      xpxo567!
Chuck Norris       cnorris      power332*
Drum Dude          ddude        jflajdljfped

In the above file, for example, Ichabod Crane is the full name, icrane is the username and qwerty123 is the password. In practice, the passwords are encrypted, but for this program, you can store them in plaintext.
Here are two sample runs of the program:

Sample Run 1

Login: rpokemon
Password: drow456

Login successful
Welcome Rayquazza Pokemon

In practice, the password is hidden when it is typed, but don’t worry about that in your program.

Sample Run2

Login: cdude
Password: trythis

Either the username or password is incorrect. You have 2 more attempts.
Login: cdude
Password: trythat

Either the username or password is incorrect. You have 1 more attempt.
Login: cdude
Password: 675rtht!
Sorry. Incorrect login. Please contact the system administrator.

What to submit: Source code, sample input file used, and sample runs of the program.