The map interface is present in java.util package represents a mapping between a key and a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The map interface is present in java.util package represents a mapping between a key and a value. The Map interface is not a subtype of the Collection interface. Therefore, it behaves a bit differently from the rest of the collection types. A map contains unique keys. Characteristics of a Map Interface 1. A Map cannot contain duplicate keys and each key can map to at most one value. Some implementations allow null key and null values like the HashMap and Linked HashMap, but some do not like the TreeMap. 2. The order of a map depends on the specific implementations. For example, TreeMap and LinkedHashMap have predictable orders, while HashMap does not. 3. There are two interfaces for implementing Map in java. They are Map and SortedMap, and three classes: HashMap, TreeMap, and Linked HashMap. Methods in Map Interface clear(): This method is used to clear and remove all of the elements or mappings from a specified Map collection. containsKey(Object): This method is used to check whether a particular key is being mapped into the Map or not. It takes the key element as a parameter and returns True if that element is mapped in the map. containsValue(Object): This method is used to check whether a particular value is being mapped by a single or more than one key in the Map. It takes the value as a parameter and returns True if that value is mapped by any of the key in the map. entrySet(): This method is used to create a set out of the same elements contained in the map. It basically returns a set view of the map or we can create a new set and store the map elements into them. equals(Object) : This method is used to check for equality between two maps. It verifies whether the elements of one map passed as a parameter is equal to the elements of this map or not. John is creating a website login page. He needs your help implement an application that will validate username and password. You need to write a program that will read a data.txt file that contains the full name, username, and password. Create a HashMap that holds username as key and the password as value. Create another HashMap that holds the username as key and full name as value. After the file is read, prompt the user to enter the username 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 is data.txt file Reynaldo Hubbard Jeffrey Roy Marcus Rocha Jackson Brewer Reynaldo Wallace Bradley Howard rhunnard jroy mrocha jbrewer rwallace bhoward Sample run 1: Enter the filename to read from: Enter username: rhunnard Enter password: qwerty123 Login successful Welcome Reynaldo Hubbard HashMap Lab public class LoginValidator { qwerty123 pa6878ss456! p$79assword123 kom@drow456 bqs! gh456!32 zexpxo77! LoginValidator.java import java.io. File; import java.io.FileNotFoundException; import java.util.HashMap; import java.util.Scanner; Sample run 2: Enter the filename to read from: Enter username: jroy Enter password: pass Either the username or the password is incorrect. You have 2 more attempts. Enter username: jroy Enter password: password Either the username or the password is incorrect. You have 1 more attempts. Enter username: jroy Enter password: pa6878ss456! Login successful Welcome Jeffrey Roy public static void main(String[] args) { // write you code here } Put all your work in ONE Zip file and submit it in Canvas. Zip filename should be in format of FirstLast_Lab7.zip (ex. JohnDoe_Lab7.zip) Zip file should contain 3 files only: (1) LoginValidator.java (2) Output.docx (screenshot of input and output) (3) Pseudo-code.docx (provide pseudo-code) The map interface is present in java.util package represents a mapping between a key and a value. The Map interface is not a subtype of the Collection interface. Therefore, it behaves a bit differently from the rest of the collection types. A map contains unique keys. Characteristics of a Map Interface 1. A Map cannot contain duplicate keys and each key can map to at most one value. Some implementations allow null key and null values like the HashMap and Linked HashMap, but some do not like the TreeMap. 2. The order of a map depends on the specific implementations. For example, TreeMap and LinkedHashMap have predictable orders, while HashMap does not. 3. There are two interfaces for implementing Map in java. They are Map and SortedMap, and three classes: HashMap, TreeMap, and Linked HashMap. Methods in Map Interface clear(): This method is used to clear and remove all of the elements or mappings from a specified Map collection. containsKey(Object): This method is used to check whether a particular key is being mapped into the Map or not. It takes the key element as a parameter and returns True if that element is mapped in the map. containsValue(Object): This method is used to check whether a particular value is being mapped by a single or more than one key in the Map. It takes the value as a parameter and returns True if that value is mapped by any of the key in the map. entrySet(): This method is used to create a set out of the same elements contained in the map. It basically returns a set view of the map or we can create a new set and store the map elements into them. equals(Object) : This method is used to check for equality between two maps. It verifies whether the elements of one map passed as a parameter is equal to the elements of this map or not. John is creating a website login page. He needs your help implement an application that will validate username and password. You need to write a program that will read a data.txt file that contains the full name, username, and password. Create a HashMap that holds username as key and the password as value. Create another HashMap that holds the username as key and full name as value. After the file is read, prompt the user to enter the username 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 is data.txt file Reynaldo Hubbard Jeffrey Roy Marcus Rocha Jackson Brewer Reynaldo Wallace Bradley Howard rhunnard jroy mrocha jbrewer rwallace bhoward Sample run 1: Enter the filename to read from: Enter username: rhunnard Enter password: qwerty123 Login successful Welcome Reynaldo Hubbard HashMap Lab public class LoginValidator { qwerty123 pa6878ss456! p$79assword123 kom@drow456 bqs! gh456!32 zexpxo77! LoginValidator.java import java.io. File; import java.io.FileNotFoundException; import java.util.HashMap; import java.util.Scanner; Sample run 2: Enter the filename to read from: Enter username: jroy Enter password: pass Either the username or the password is incorrect. You have 2 more attempts. Enter username: jroy Enter password: password Either the username or the password is incorrect. You have 1 more attempts. Enter username: jroy Enter password: pa6878ss456! Login successful Welcome Jeffrey Roy public static void main(String[] args) { // write you code here } Put all your work in ONE Zip file and submit it in Canvas. Zip filename should be in format of FirstLast_Lab7.zip (ex. JohnDoe_Lab7.zip) Zip file should contain 3 files only: (1) LoginValidator.java (2) Output.docx (screenshot of input and output) (3) Pseudo-code.docx (provide pseudo-code)
Expert Answer:
Answer rating: 100% (QA)
Below is the code for the LoginValidatorjava file based on the requirements mentioned java import ja... View the full answer
Related Book For
Cost Benefit Analysis Concepts and Practice
ISBN: 978-0137002696
4th edition
Authors: Anthony Boardman, David Greenberg, Aidan Vining, David Weimer
Posted Date:
Students also viewed these programming questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Verify that (x, y) = tan 1 y/x is harmonic using both the rectangular and polar expressions for .
-
The trial balance for Lindor Corporation, a manufacturing company, for the year ended December 31, 2018, included the following income accounts: The trial balance does not include the accrual for...
-
What is a response surface? For a regression model with seven independent variables, what is the dimensionality of the response surface?
-
Describe how the principles of operant learning theory and social cognitive theory can be used to manage workplace diversity and reduce the effects of workplace stereotypes. How can the...
-
1. What are the ethical issues in this situation? Which issues must Berlex consider first when determining how to distribute Betaseron? 2. Given the shortage of the drug, how should Berlex decide who...
-
1.Assume that the firm's market value of equity, S, is a call option written on the market value of the firm, V, with exercise price equal to the face value of the firm's risky debt, D. The debt is a...
-
Finley Heaters Inc. is a mid sized manufacturer of residential water heaters. Sales have grown during the last several years, and the companys production capacity needs to be increased. The companys...
-
On September 6, 2014, East River Tug Co. purchased a new tugboat for $400,000. The estimated life of the boat was 20 years, with an estimated residual value of $40,000. Compute the depreciation on...
-
Assume Andys and Helens behavior at home is partially regulated by their condominium association, which acts as a small voluntary government for its residents. a) Per the Coase Theorem, how might the...
-
1 Jae had a visit to Charlotte. When he returns, he had two flights, one from Charlotte to Atlanta and another one from Atlanta to Columbia. Calculate the total displacement of his moving from...
-
Consider the advances you have made in studying more productively over the past two years or so (e.g. from high school to 2nd-year university). Describe the specific methods you have used to improve...
-
Are both methods (i.e. NPV and IRR) good in these situations?What would you do if you were the one in Sinning?s position?According to your opinion, which project is better for thiscompany? Making the...
-
You have a spinner that as equal probabilities of landing on any number from 1 to 8, inclusive. Find the probability that the spinner will stop on an even number or a number greater than 5. (You do...
-
Show that the Bcklund transformations: Py - Vy = VZelotu)/2 connect to partial differential equation y = Ojand Liouville's equation yy = e Also use the solution of b = 0 in the Bcklund...
-
Apply Jacobis method to the given system. Take the zero vector as the initial approximation and work with four-significant-digit accuracy until two successive iterates agree within 0.001 in each...
-
Five years ago a community college district established programs in ten new vocational fields. The district now wants to phase out those programs that are not performing successfully and retain those...
-
A government data processing center has been plagued in recent years by complaints from employees of back pain. Consultants have estimated that upgrading office furniture at a net cost of $425,000...
-
An analyst for a municipal public housing agency explained the choice of a discount rate as follows: Our agency funds its capital investments through nationally issued bonds. The effective interest...
-
Using data on 1000 home loan borrowers, we estimate the linear probability model where \(D E F A U L T=1\) if the borrower has made a mortgage payment more than 90 days late, \(L T V=100\) (loan...
-
We have \(N=396\) observations on employment at fast-food restaurants in two neighboring states, New Jersey and Pennsylvania. In Pennsylvania, the control group \(d_{i}=0\), there is no minimum wage...
-
A sample of 200 Chicago households was taken to investigate how far American households tend to travel when they take a vacation. Consider the model MILES is miles driven per year, INCOME is measured...
Study smarter with the SolutionInn App