Question

Hashmap concept

HashMap:  We can use a HashMap to store key value pairs.  Reminder that only reference types can be used as the key or value.  It you want to use a number as the key then an Integer data type could be used but not an int primitive data type.

Create a class called Login which contains a HashMap as a private attribute.  It should also have an instance method called loadCredentials which accepts the two arrays.  It will load the HashMap with key/value pairs based on the two arrays below. The userNames should be the keys and the passwords the values.  The purpose of the HashMap is to allow us to obtain the user’s password given their username as the key. 

private static String[] userNameArray = {"John", "Steve", "Bonnie", "Kylie", "Logan", "Robert"};

private static String[] passwordArray = {"1111", "2222", "3333", "4444", "5555", "6666"};  

Create a login method in the Login class.  This method will prompt the user for a username and password. It will then return true or false based on whether or not the user enters valid username and password.  Note that the username should exist and the password associated with that username should match what is stored for that username in the hashmap.

 

Login

-userMap: HashMap<String,   String>

+loadCredentials(String[],   String[]): void

+login: boolean

 

When the tutor application starts.  Call the method to ensure the credentials are loaded and pass the two arrays provided above.  Then continually prompt the user to login until they enter a valid username and password.  Provide an error message if login fails.  Once a valid username and password is entered the main menu is shown to the user and the program runs normally.

 

Sample I/O

Please login:
  Username:
  Sylvain                                        
ß Note that the user can enter   a username that does not exist
  Invalid login, please try again.
  Username:
  Bob
  Invalid login, please try again.
  Username:
  John
  Password:
  1234                                          
ß Note that the user can enter   an invalid password
  Invalid login, please try again.
  Username:
  John
  Password:
  1111

Welcome John                        ß Welcome based on the userName

Welcome to CIS Tutoring   (2021-02-22)

-------------------------

- CIS Menu

- 1-Add An Invoice

- 2-Show Total So Far

- 3-Show All Invoices

- 4-Show All Distinct   Employees

- X-eXit

-------------------------

Option-->

 

 

 


0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Hashmap concept
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Create a class called Login which contains a HashMap as a private attribute. It should also...

    Create a class called Login which contains a HashMap as a private attribute. It should also have an instance method called loadCredentials which acccepts the two arrays. It will load the Hash Map with key/value pairs based on the two arrays above. The userNames should be the keys and the passwords the values. private static String[] userNameArray = {"John", "Steve", "Bonnie", "Kylie", "Logan", "Robert"); private static String) passwordArray = {"1111", "2222", "3333", "4444", "5555", "6666"}; Create a login method in...

  • ATM MACHINE

    Kindly help me In this assignment you will create a RMI based system that allows a user to do the following: 1) Create a bank account by supplying a user id and password. 2) Login using their id and password. 3) Quit the program. Main Manu of ATM service window *Separate remote methods will be created for all of these functionalities. ->To create account see output below Hi! Welcome to  ATM Machine! Please select an option from the menu below: l -> Loginc -> Create New Account q -> Quit > c...

  • in python 5.23 Login Create a program that prompts the user for a username and password....

    in python 5.23 Login Create a program that prompts the user for a username and password. The correct username should be python and the correct password should be csci 135. See below for example output. (Different messages depending on if user name or password are correct.) Only allow the user to make 3 attempts. Welcome to my secret program! Please enter your username: Trish Please enter your password: Duce Invalid username and password Please enter your username: Trish Please enter...

  • Can someone fix the program below so it does what the picture says it won't work...

    Can someone fix the program below so it does what the picture says it won't work for me. import java.util.Scanner; public class Userpass { static String arr[]; static int i = 0; public static void main(String[] args) { String username, password; int tries = 0, result; do { System.out.print("Enter the username: "); username = readUserInput(); System.out.print("Enter the password: "); password = readUserInput(); result = verifyCredentials(username, password); tries++; if (result == -1) System.out.println("The username is incorrect!\n"); else if (result == -2)...

  • What am I doing wrong? I get this error: "The name 'LoginPasswordUserControl' does not exist in...

    What am I doing wrong? I get this error: "The name 'LoginPasswordUserControl' does not exist in the current context" I have a user control, here is the code: using System.Windows.Forms; //Define the namespace to make the user control. //namespace to hold the application namespace LoginPasswordUser { //Define the class to make the user control.   //Class to define the control   public partial class LoginPasswordUserControl : UserControl { //Define the read-only properties to get the username and the password from the user...

  • Lab 4: Databased Admin Tool Continued Python Objective: In the previous lab, you developed an admin tool for username an...

    Lab 4: Databased Admin Tool Continued Python Objective: In the previous lab, you developed an admin tool for username and password management. You accomplished the tasks with Dictionary or List. Here, use class to design your own data structure to accomplish a similar task. The UD.txt datafile: FIRST NAME, LAST NAME,USERNAME,PASSWORD Sam, DDal,sdd233,Pad231 Dave, Dcon,dcf987, BHYW4fw Dell, Grant,dgr803,Sb83d2d Mike, Kress,mkr212,UNNHS322 Lisa,Kate,lki065,dgw6234 Paul,Edward,ped332,9891ds Youyou,Tranten,ytr876,dsid21kk Nomi,Mhanken,nmh223,3282jd3d2 Write a program that imports the database from UD.txt, your program can search for users’ password....

  • Java: Please help with my Tester. I'm having a hard time figuring out my error. Thank...

    Java: Please help with my Tester. I'm having a hard time figuring out my error. Thank you. What the tester requires: The AccountTester This class should consists of a main method that tests all the methods in each class, either directly by calling the method from the Tester or indirectly by having another method call a method. User and Bot information will be read from a file. A sample file is provided. Use this file format to aid in grading....

  • This project will use The Vigenere Cipher to encrypt passwords. Simple letter substitution ciphers are ones...

    This project will use The Vigenere Cipher to encrypt passwords. Simple letter substitution ciphers are ones in which one letter is substituted for another. Although their output looks impossible to read, they are easy to break because the relative frequencies of English letters are known. The Vigenere cipher improves upon this. They require a key word and the plain text to be encrypted. Create a Java application that uses: decision constructs looping constructs basic operations on an ArrayList of objects...

  • in java Complete Program that simulates a login procedure. The program reads a list of names,...

    in java Complete Program that simulates a login procedure. The program reads a list of names, email addresses and passwords from a file p3.txt. Store the information in parallel array lists names, emails and passwords. Your program will prompt the user for their email address. If the email is not in the system, prompt the user to try again. Provide the option to quit. If the email is found in the system, prompt the user to enter their password. After...

  • I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for.....

    I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols !.@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT