Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 18.3, Problem 18.22CP
Explanation of Solution
Name of the method called to get an object’s hash code:
The “hashCode()” method is called to get an object’s hash code in the program.
- The hash code is an integer value, which is a characteristic of an object.
- The hashing
algorithm is used to evaluate a hash code for an object. - Different objects in the code can contain the same data and a hashing algorithm should give the same hash code for those objects.
Example:
//store the string value into the variable
String str1 = new String ("Barney");
String str2...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Bean Scopes
Suppose you are working on an application that involves encrypting passwords before storing them in the database. The encryption part is carried out by a PasswordEncryptor class. This class provides you with a method that takes a plaintext password and returns an encrypted one. You need to create a bean of this class. What should be the scope of this bean? Choose the correct option from those given below.
(Hint: PasswordEncryptor only contains methods and no fields to maintain state. Hence, we need to create a stateless bean of PasswordEncryptor. Recall which bean scope is used for creating stateless beans.)
1) Prototype
2) Singleton
3) Request
4) SessionProvide right solution
The compareTo method. First you compare this.ticker which is a String, then if they are the same then you compare by the this.purchasePrice which is a double
hashCode
public int hashCode()
The hashCode method using the Code-> Generate equals and hashCode with no changes
Overrides:
hashCode in class Object
Returns:
int Representing the hashCode
compareTo
public int compareTo(Stock another)
The compareTo method not auto generated Compares first by ticker and if the tickers are the same secondarily compares by price
Specified by:
compareTo" in interface Comparable<stock>
Parameters:
another - the object to be compared.
Returns:
int Representing order
Throws:
IllegalArgumentException"- if another is null.
What are the requirements for using an object as a HashMap key or value?
Chapter 18 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 18.1 - Prob. 18.1CPCh. 18.1 - What are the three general types of collections?Ch. 18.1 - Prob. 18.3CPCh. 18.1 - Prob. 18.4CPCh. 18.1 - Prob. 18.5CPCh. 18.1 - Prob. 18.6CPCh. 18.1 - Prob. 18.7CPCh. 18.2 - Prob. 18.8CPCh. 18.2 - Prob. 18.9CPCh. 18.2 - Prob. 18.10CP
Ch. 18.2 - Prob. 18.11CPCh. 18.2 - Prob. 18.12CPCh. 18.2 - Prob. 18.13CPCh. 18.2 - Prob. 18.14CPCh. 18.2 - Prob. 18.16CPCh. 18.2 - Prob. 18.17CPCh. 18.2 - Prob. 18.18CPCh. 18.2 - Prob. 18.20CPCh. 18.3 - Prob. 18.21CPCh. 18.3 - Prob. 18.22CPCh. 18.3 - Prob. 18.23CPCh. 18.3 - Prob. 18.24CPCh. 18.3 - Any time you override the Object classs equals...Ch. 18.3 - Prob. 18.26CPCh. 18.3 - Prob. 18.27CPCh. 18.3 - Prob. 18.28CPCh. 18.4 - Prob. 18.29CPCh. 18.4 - Prob. 18.31CPCh. 18.4 - Prob. 18.32CPCh. 18.6 - How do you define a stream of elements?Ch. 18.6 - How does a stream intermediate operation differ...Ch. 18.6 - Prob. 18.35CPCh. 18.6 - Prob. 18.36CPCh. 18.6 - Prob. 18.37CPCh. 18.6 - Prob. 18.38CPCh. 18.6 - Prob. 18.39CPCh. 18 - Prob. 1MCCh. 18 - Prob. 2MCCh. 18 - This type of collection is optimized for...Ch. 18 - Prob. 4MCCh. 18 - A terminal operation in a stream pipeline is also...Ch. 18 - Prob. 6MCCh. 18 - Prob. 7MCCh. 18 - This List Iterator method replaces an existing...Ch. 18 - Prob. 9MCCh. 18 - Prob. 10MCCh. 18 - This is an object that can compare two other...Ch. 18 - This class provides numerous static methods that...Ch. 18 - Prob. 13MCCh. 18 - Prob. 14MCCh. 18 - Prob. 15TFCh. 18 - Prob. 16TFCh. 18 - Prob. 17TFCh. 18 - Prob. 18TFCh. 18 - Prob. 19TFCh. 18 - Prob. 20TFCh. 18 - Prob. 21TFCh. 18 - Prob. 22TFCh. 18 - Prob. 1FTECh. 18 - Prob. 2FTECh. 18 - Prob. 3FTECh. 18 - Prob. 4FTECh. 18 - Write a statement that declares a List reference...Ch. 18 - Prob. 2AWCh. 18 - Assume that it references a newly created iterator...Ch. 18 - Prob. 4AWCh. 18 - Prob. 2SACh. 18 - Prob. 4SACh. 18 - Prob. 5SACh. 18 - Prob. 6SACh. 18 - How does the Java compiler process an enhanced for...Ch. 18 - Prob. 8SACh. 18 - Prob. 9SACh. 18 - Prob. 10SACh. 18 - Prob. 11SACh. 18 - Prob. 12SACh. 18 - Prob. 13SACh. 18 - Prob. 14SACh. 18 - Word Set Write an application that reads a line of...Ch. 18 - Prob. 3PCCh. 18 - Prob. 5PCCh. 18 - 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
- In Perl Please Set up a hash that contains a few city names and their corresponding zip codes (guess if you don’t know them). Then, display the names of the cities and ask the user to enter one. Display the corresponding zip code. Reverse the hash and display the zip codes, asking the user to choose one. Display the city for that zip code. You can display the lists of cities and zip codes any way you want, or display both at the same time with the keys function,arrow_forwardIs it feasible to store a HashMap with a duplicate key?arrow_forwardQuestion 12arrow_forward
- Question1- Add to the Test class a method called isSubSet(LinearProbingHashTable h1, LinearProbingHashTable h2) that is receives 2 hash tables h1 and h2, and returns true if h1 is sub set of h2, otherwise the method returns false. Don't forget to test the method in the main of Test classarrow_forwardWhich of the following methods is a method of wrapper Integer for obtaining hash code for the invoking object? a) int hash() b) int hashcode() c) int hashCode() d) Integer hashcode()arrow_forwardCreate struct HashNode and class HashTable that will be used to store students' data. For each student, it'll store the ID (string) as the key, and the first name (string), last name (string), and email (string) as the value. You can imagine a single HashNode as follows: "123456789" "Jessica" "Wolf" "abcdef@bartleby.com" HashTable should have the following attributes and methods: Attributes 1. The dynamic array that stores the data. 2. The number of elements currently stored. 3. The maximum number of elements the container can store. Methods 1. Constructor that takes from the user the maximum size of the container. 2. void insert(string ID, string firstName, string lastName, string email): uses the following hash function h2(h1(ID)) to map the key to a specific index in the table: • h1(ID): ww IDLength -1 Σ ID • h2(K) -> [0, N-1], where N is the table size In case the index that the hash function generated was already full, the insert function should add the student information in a…arrow_forward
- The operator is a basic hash technique that may be used to translate a collection of numbers into array positions.arrow_forwardWhich index is also reffered to as a clustring index? Secondary index Bidirectional index Primary index Hash Indexarrow_forwardWrite code to create three instances of a HashMap class. Give two the same, and the third different data. Compare the objects and state the resultarrow_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