Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 4 HashMap Background This activity will require you to use a HashMap during coding of the login for the application. HashMap: We can use

Assignment 4 HashMap

Background

This activity will require you to use a HashMap during coding of the login for the application.

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 above. The userNames should be the keys and the passwords the values. The purpose of the HashMap is to allow us to obtain the users 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: HashSet

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

+login: boolean

When the flower shop 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-->

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions

Question

What is a token bucket and how does it work?

Answered: 1 week ago

Question

Define organisational structure

Answered: 1 week ago

Question

Define line and staff authority

Answered: 1 week ago

Question

Define the process of communication

Answered: 1 week ago

Question

Explain the importance of effective communication

Answered: 1 week ago

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago