Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
3rd Edition
ISBN: 9780134038179
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 19, Problem 11SA
Program Plan Intro
“hashCode” method:
- The hash code is an integer value which is the characteristic of an object.
- The hashing
algorithm is used to evaluate a hash code for an object. - Different objects in the code contain same data and a hashing algorithm should give the same hash code for both.
- For example, if the user wants to evaluate the hash code for a string, he would use the characters making up the string in the calculation. Possibly the user would use each character’s Unicode value in a mathematical formula which would give us an integer value.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
You have been provided with the following elements:
• Motherland
England
• Brothers
• Sisters
• Wonders
Write a Java program that creates a HashSet. Your Java program must use the methods in the
HashSet interface to do the following:
(i)
Add the above elements into the HashSet.
(ii) Display all the elements in the HashSet.
(iii) Remove the elements in the HashSet that contain the word "land" and display the
remaining elements in the HashSet.
Code to start with:
public void addStudents(String[] ids){ }
TODO: Create a hash function and compute the index of a user using both the first and last names.
Chapter 19 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Ch. 19.1 - Prob. 19.1CPCh. 19.1 - What are the three general types of collections?Ch. 19.1 - Prob. 19.3CPCh. 19.1 - Prob. 19.4CPCh. 19.1 - Prob. 19.5CPCh. 19.1 - Prob. 19.6CPCh. 19.1 - Prob. 19.7CPCh. 19.2 - Prob. 19.8CPCh. 19.2 - Prob. 19.9CPCh. 19.2 - Prob. 19.10CP
Ch. 19.2 - Prob. 19.11CPCh. 19.2 - Prob. 19.12CPCh. 19.2 - Prob. 19.13CPCh. 19.2 - Prob. 19.14CPCh. 19.2 - Prob. 19.16CPCh. 19.2 - Prob. 19.17CPCh. 19.2 - Prob. 19.18CPCh. 19.2 - Prob. 19.20CPCh. 19.3 - Prob. 19.21CPCh. 19.3 - Prob. 19.22CPCh. 19.3 - Prob. 19.23CPCh. 19.3 - Prob. 19.24CPCh. 19.3 - Any time you override the Object classs equals...Ch. 19.3 - Prob. 19.26CPCh. 19.3 - Prob. 19.27CPCh. 19.3 - Prob. 19.28CPCh. 19.4 - Prob. 19.29CPCh. 19.4 - Prob. 19.31CPCh. 19.4 - Prob. 19.32CPCh. 19.6 - How do you define a stream of elements?Ch. 19.6 - How does a stream intermediate operation differ...Ch. 19.6 - Prob. 19.35CPCh. 19.6 - Prob. 19.36CPCh. 19.6 - Prob. 19.37CPCh. 19.6 - Prob. 19.38CPCh. 19.6 - Prob. 19.39CPCh. 19 - Prob. 1MCCh. 19 - Prob. 2MCCh. 19 - This type of collection is optimized for...Ch. 19 - Prob. 4MCCh. 19 - A terminal operation in a stream pipeline is also...Ch. 19 - Prob. 6MCCh. 19 - Prob. 7MCCh. 19 - This List Iterator method replaces an existing...Ch. 19 - Prob. 9MCCh. 19 - Prob. 10MCCh. 19 - This is an object that can compare two other...Ch. 19 - This class provides numerous static methods that...Ch. 19 - Prob. 13MCCh. 19 - Prob. 14MCCh. 19 - Prob. 15TFCh. 19 - Prob. 16TFCh. 19 - Prob. 17TFCh. 19 - Prob. 18TFCh. 19 - Prob. 19TFCh. 19 - Prob. 20TFCh. 19 - Prob. 21TFCh. 19 - Prob. 22TFCh. 19 - Prob. 1FTECh. 19 - Prob. 2FTECh. 19 - Prob. 3FTECh. 19 - Prob. 4FTECh. 19 - Write a statement that declares a List reference...Ch. 19 - Prob. 2AWCh. 19 - Assume that it references a newly created iterator...Ch. 19 - Prob. 4AWCh. 19 - Prob. 2SACh. 19 - Prob. 4SACh. 19 - Prob. 5SACh. 19 - Prob. 6SACh. 19 - How does the Java compiler process an enhanced for...Ch. 19 - Prob. 8SACh. 19 - Prob. 9SACh. 19 - Prob. 10SACh. 19 - Prob. 11SACh. 19 - Prob. 12SACh. 19 - Prob. 13SACh. 19 - Prob. 14SACh. 19 - Word Set Write an application that reads a line of...Ch. 19 - Prob. 3PCCh. 19 - Prob. 5PCCh. 19 - Prob. 8PC
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Scrabble Help: The file dictionary.txt contains all of the words in the Official Scrabble Player's Dictionary, Second Edition. Note: this list contains some offensive language. Write a class, WordLists, in Java that generates useful word lists for scrabble players using this list. Your class should contain the following methods: WordLists(String fileName): a constructor that takes the name of the dictionary file as the only parameter. lengthN(int n): returns an ArrayList of all length n words (Strings) in the dictionary file. endsWith(char lastLetter, int n): returns an ArrayList of words of length n ending with the letter lastLetter containsLetter(char included, int index, int n): returns an ArrayList of words of length n containing the letter included at position index. So for example the word "cannon" would be on the list returned by containsLetter('o',6,4) because it contains the letter 'o', at index 4, and is length 6. multiLetter(int m, char included): returns an ArrayList of…arrow_forwardJava Code: Add a HashMap to your Lexer class and initialize all the keywords. Change your lexer so that it checks each string before making the WORD token and creates a token of the appropriate type if the work is a key word. When the exact type of a token is known, you should NOT fill in the value string, the type is enough. For tokens with no exact type we still need to fill in the token’s string. Rename “WORD” to “IDENTIFIER”. Strings and characters will require some additions to your state machine. Create “STRINGLITERAL” and “CHARACTERLITERAL” token types. These cannot cross line boundaries. Your lexer should throw an exception if it encounters a character that it doesn’t expect outside of a comment, string literal or character literal. Create a new exception type that includes a good error message and the token that failed. Ensure that the ToString method prints nicely. Add “line number” to your Token class. Keep track of the current line number in your lexer and populate each…arrow_forwardQuestion1- Add to the class ChainingHashTable a method called search( E data) that is receives a generic type of data, and returns the index where this data is stored in the hash table. If the data does not exist then return -1. Don't forget to test the method in the main of Test class, if the returned value is -1 then display the data does not exist in the hash table, otherwise, display the index value.arrow_forward
- code: public class PasswordGeneratorAndStorage {/*** Adds an application to the applications ArrayList. If index is -1, add application* to the end of applications. Else is index is within the size of applications, add* application at that index in applications. Otherwise, return. However, if applications * or application is null, return.* * @param applications* @param application* @param index*/public static void addApplication(ArrayList<String> applications, String application, int index) {// TODO: FILL IN BODY}/*** Generates a random password of length passwordLength and adds it to the end of* passwords if index is -1, or adds it to the index of passwords if index is within the* size of passwords (similar to how the addApplication adds an application). To generate* the random password, use rand to generate a random int within the size of characters. You* can then use this int to grab the char at that index in characters and concatenate that* to your String password variable.…arrow_forwardBooksMan import java.util.HashMap; import java.util.ArrayList; class Book{ String title, ISBN; ArrayList authors; public Book (String title, String ISBN, String authors){ this.title = title; this.ISBN = ISBN; this.authors = new ArrayList(); if (authors != null) { String [] authorArray = authors.split(", "); for (int i = 0; i < authorArray.length; i++) { this.authors.add(authorArray[i]); } } } public String getISBN() { return ISBN; } public String getTitle() { return title; } public ArrayList getAuthors() { return authors; } } public class Main { public static HashMap buildMap(Book[] s) { HashMap books = new HashMap(); if (s != null) { // TODO Write the statements here: to manage each book from the parameter array reference to the hashmap } return books; } public static void main(String argv[]) { Book[] bookArray = new Book[4]; for (int i = 0; i < 4; i++) {…arrow_forwardTrue or False: Given the below code and assuming all syntax is correct, at Point 1, "3" is printed to the console: HashSet-String> hs = new HashSet-String>0; hs.adda"); ha addb); hs adda"); Syrtem.out printinchs size(), // Point 1 True Falsearrow_forward
- Write in C Language Frequent Letter Your Facebook account has just been hacked and you want to change its password. To create a strongpassword, Facebook just recommended you two strings S and T, each contains N lowercase English letters. You want to choose a password containing N lowercase English letters such that the i th character is either the i th character of S or the i th character of T. For example, if S = icyz and T = ixpc, then there are 8 different passwords that you can choose: icyz, icyc, icpz, icpc, ixyz, ixyc, ixpz, ixpc. The strength of your password is defined as the number of occurences of the most frequent letter. For example, the strength of icyz is 1 and the strength icpc is 2. You are wondering what is the strength of the strongest password that you can choose.arrow_forwardJava Code: Look through the Language Description and build a list of keywords. Add a HashMap to your Lexer class and initialize all the keywords. Change your lexer so that it checks each string before making the WORD token and creates a token of the appropriate type if the work is a key word. When the exact type of a token is known (like “WHILE”), you should NOT fill in the value string, the type is enough. For tokens with no exact type (like “hello”), we still need to fill in the token’s string. Finally, rename “WORD” to “IDENTIFIER”. Similarly, look through the Language Description for the list of punctuation. A hash map is not necessary or helpful for these – they need to be added to your state machine. Be particularly careful about the multi-character operators like := or >=. These require a little more complexity in your state machine. Strings and characters will require some additions to your state machine. Create “STRINGLITERAL” and “CHARACTERLITERAL” token types. These…arrow_forwardplease help me this simple operation question 2. spam = [['cat', 'bat'], [10, 20, 30, 40, 50]]spam[0]: spam[-1]: spam[1:1]arrow_forward
- 50 O이 습 @0verride public boolean equals(Object object) { if (object instanceof Point ){ Point point = (Point)object; 51 52 53 return (x point.x) && (y == point.y); == 54 55 else 56 return false; 57 } 58 O이 @0verride public int hashCode () { return Objects.hash(x,y); } 61 62 /* 63 tostring: default string format for this class 64 output: 65 String: (x,y) (no spaces) 66 67 O이 @0verride public String tostring(){ } public static void main(String[] args) { /* create point p = (2,3) using keyword new */ System.out.println("p=" + p); 68 69 70 71 72 73 74 /* create point q using p.getLocation() */ System.out.println("q="+q); 75 76 77 78 79 /* translate q up 3 and left 1 */ 80 81 System.out.println("q="+q); 82 /* make q refer to p */ System.out.println("q="+q); 83 84 85 86 87 88 } 89 D-D-arrow_forward7- question What keys and values are contained in the following map after execution of the following piece of code? Map map = new HashMap (); map.put (8, "Eight"); map.put (41, "Forty-one"); map.put (8, "Ocho"); map.put (18, "Eighteen"); map.put (50, "Fifty"); map.put (132, "OneThreeTwo"); map.put (28, "Twenty-eight"); map.put (79, "Seventy-nine"); map.remove ( 41); map.remove (28); map.put (28, "18"); map.remove (18); a. {8=Eight, 41=Forty-one, 8=0cho, 18=Eighteen, 50=Fifty, 132=OneThreeTwo, 28=Twenty-eight, 79=Seventy-nine, 28=18} b. {8=Eight, 8=Ocho, 50=Fifty, 132=OneThreeTwo, 79=Seventy-nine, 28=18} c. {50=Fifty, 132=DOneThreeTwo, 8=Ocho, 28=18, 79=Seventy-nine} d. {8=Eight, 50=Fifty, 132=OneThreeTwo, 79=Seventy-nine, 28=18}arrow_forwardJavaarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education