BIG JAVA: LATE OBJECTS
2nd Edition
ISBN: 9781119626220
Author: Horstmann
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Question
Chapter 16, Problem 14PP
Program Plan Intro
To implement a hash table with open addressing
Program plan:
- In a file “HashSet.java”, import necessary package, and create a class “HashSet”,
- Declare the array of “Object” type.
- Declare the necessary variable.
- Define the method “getBucketsSize()” to get the length of the bucket.
- Define the constructor to create a hash table.
- Create an array and set the current size to “0”.
- Define the method “toString()” that returns the string representation of array.
- Define the method “contains()”,
- Assign the hash code.
- Check the condition,
- If it is true, returns true.
- Create a loop,
-
- Check the condition,
- If it is true, returns true.
- Check whether the bucket value contains null,
- If it is true, returns false.
- Check the condition,
- If it is true, returns true.
- Define the method “getHashCode()”,
- Assign the hash code.
- Check whether the value is less than “0”,
- If it is true, assign the negative value.
- Update the hash value.
- Return the hash code.
- If it is true, assign the negative value.
- Define the method “add()”
- Check whether there is a room before probing,
- If it is true, call the method “resizeTable()()”.
- Assign the hash code returned from the method “getHashCode()”.
- Check whether the has value is a null,
-
- If it is true, assign the object properties.
- Otherwise, execute a loop,
-
- Check whether the bucket contains null value,
- If it is true, assign the object properties.
- Use break statement.
- Otherwise, Check the condition,
- Returns false.
- Check whether the bucket contains null value,
- Increment the current size.
- Returns true.
- If it is true, call the method “resizeTable()()”.
- Check whether there is a room before probing,
- Define the method “remove()” to remove the object from the set,
- Get the hash code.
- Set the position to “-1”.
- Check the condition,
- If it is true, assign the hash code to position.
- Create a loop,
-
- Check the condition, set the new position.
- Check whether the position value is “-1”,
-
- If it is true, returns false.
- If the item found, find the last item in the rest of the probing sequence.
- Create a loop,
-
- Check whether the current bucket value contains null,
- If it is true, assign the current value.
- Otherwise, check the condition,
- If it is true, assign the current value to last found.
- Check whether the current bucket value contains null,
- Check whether the end sequence is “-1”,
-
- If it is true, use conditional operator to find the end sequence.
- Check the whether the last found is “-1”,
-
- Assign the value to position.
- Assign the null value to last found.
- Decrement the current size.
- Create a loop,
- Check whether the bucket is not full,
- Decrement the size.
- Assign the value.
- Assign the null value to the bucket.
- Call the method “add()”.
- Check whether the bucket is not full,
- Otherwise,
-
- Assign null value to current bucket position.
- Decrement the size.
- Returns true.
- If it is true, assign the hash code to position.
- Define the method “iterator ()” to return an iterator that traverse the set elements,
- Return the object of “HashSetIterator()”.
- Define the method “size()” to return the size.
- Define the method “resizeTable()”,
- Create an object.
- Make a copy of bucket.
- Assign the temporary value.
- Set the current size to “0”.
- Create a loop,
- Check the condition, and if it is true, call the method “add()”.
- Create a class “HashSetIterator”,
- Declare the variable to denote bucket index.
- Define the constructor that create a hash set iterator that points to the first element of the hash set.
- Define the method “hasNext ()”,
- Create a loop,
- Check the condition,
-
- Returns true.
- Returns false.
- Create a loop,
- Define the method “next ()”,
- Execute the statement without checking the condition,
- Increment the index.
- Check the condition,
- If it is true, create an object for “NoSuchElementException”.
- Check whether the current bucket value contains null,
- Return the value.
- Execute the statement without checking the condition,
- Define the method “remove()”,
- Throw an exception “UnsupportedOperationException”.
- In a file “HashSetTest.java”, create a class “HashSetTest”,
- Define the method “main()”,
- Create an object for “HashSet”.
- Add the name “James” into the set.
- Add the name “David” into the set.
- Add the name “John” into the set.
- Add the name “Kean” into the set.
- Add the name “Juliet” into the set.
- Add the name “Cassendra” into the set.
- Print the set and expected output.
- Remove the name “John” from the set.
- Print the set and expected output.
- Define the method “main()”,
Expert Solution & Answer

Want to see the full answer?
Check out a sample textbook solution
Students have asked these similar questions
I need to make a parallel version of this sequential code.
Benefits of using arrays as instance variables: What are the advantages of incorporating arrays as instance variables within a class?
Initializing and managing arrays: How do you initialize and manage arrays within class constructors and mutators (setters)?
Example of using arrays as instance variables: Share an example where you have used arrays as instance variables and discuss its application in a real-world scenario.
Common mistakes with arrays as instance variables: What are some common mistakes to avoid when working with arrays as instance variables?
Information hiding violations: What is the potential violation of information hiding when using arrays as instance variables? How can this be resolved?
Do you think that computers should replace teachers? Give three references with your answer.
Chapter 16 Solutions
BIG JAVA: LATE OBJECTS
Ch. 16.1 - Prob. 1SCCh. 16.1 - Prob. 2SCCh. 16.1 - Prob. 3SCCh. 16.1 - Prob. 4SCCh. 16.1 - Prob. 5SCCh. 16.1 - Prob. 6SCCh. 16.1 - Prob. 7SCCh. 16.2 - Prob. 8SCCh. 16.2 - Prob. 9SCCh. 16.2 - Prob. 10SC
Ch. 16.2 - Prob. 11SCCh. 16.2 - Prob. 12SCCh. 16.3 - Prob. 13SCCh. 16.3 - Prob. 14SCCh. 16.3 - Prob. 15SCCh. 16.3 - Prob. 16SCCh. 16.3 - Prob. 17SCCh. 16.3 - Prob. 18SCCh. 16.4 - Prob. 19SCCh. 16.4 - Prob. 20SCCh. 16.4 - Prob. 21SCCh. 16.4 - Prob. 22SCCh. 16.4 - Prob. 23SCCh. 16.4 - Prob. 24SCCh. 16 - Prob. 1RECh. 16 - Prob. 2RECh. 16 - Prob. 3RECh. 16 - Prob. 4RECh. 16 - Prob. 5RECh. 16 - Prob. 6RECh. 16 - Prob. 7RECh. 16 - Prob. 8RECh. 16 - Prob. 9RECh. 16 - Prob. 10RECh. 16 - Prob. 11RECh. 16 - Prob. 12RECh. 16 - Prob. 13RECh. 16 - Prob. 14RECh. 16 - Prob. 15RECh. 16 - Prob. 16RECh. 16 - Prob. 17RECh. 16 - Prob. 18RECh. 16 - Prob. 19RECh. 16 - Prob. 20RECh. 16 - Prob. 21RECh. 16 - Prob. 22RECh. 16 - Prob. 23RECh. 16 - Prob. 24RECh. 16 - Prob. 25RECh. 16 - Prob. 26RECh. 16 - Prob. 1PECh. 16 - Prob. 2PECh. 16 - Prob. 3PECh. 16 - Prob. 4PECh. 16 - Prob. 5PECh. 16 - Prob. 6PECh. 16 - Prob. 7PECh. 16 - Prob. 8PECh. 16 - Prob. 9PECh. 16 - Prob. 10PECh. 16 - Prob. 11PECh. 16 - Prob. 12PECh. 16 - Prob. 13PECh. 16 - Prob. 14PECh. 16 - Prob. 15PECh. 16 - Prob. 16PECh. 16 - Prob. 17PECh. 16 - Prob. 18PECh. 16 - Prob. 19PECh. 16 - Prob. 20PECh. 16 - Prob. 21PECh. 16 - Prob. 1PPCh. 16 - Prob. 2PPCh. 16 - Prob. 3PPCh. 16 - Prob. 4PPCh. 16 - Prob. 5PPCh. 16 - Prob. 6PPCh. 16 - Prob. 7PPCh. 16 - Prob. 8PPCh. 16 - Prob. 9PPCh. 16 - Prob. 10PPCh. 16 - Prob. 11PPCh. 16 - Prob. 12PPCh. 16 - Prob. 13PPCh. 16 - Prob. 14PPCh. 16 - Prob. 15PPCh. 16 - Prob. 16PPCh. 16 - Prob. 17PP
Knowledge Booster
Similar questions
- Is online learning or face to face learning better to teach students around the around the world? Give reasons for your answer and provide two references with your response. What are benefits of both online learning and face to face learning ? Give two references with your answer. How does online learning and face to face learning affects students around the world? Give two references with your answer.arrow_forwardExplain Five reasons if computers should replace teachers. Provide three references with your answer. List three advantages and three disadvantages face to face learning and online learning may have on children. Provide two references with your answer.arrow_forwardYou were requested to design IP addresses for the following network using the address block 10.10.10.0/24. Specify an address and net mask for each network and router interfacearrow_forward
- For the following network, propose routing tables in each of the routers R1 to R5arrow_forwardFor the following network, propose routing tables in each of the routers R1 to R5arrow_forwardUsing R language. Here is the information link. http://www.cnachtsheim-text.csom.umn.edu/Kutner/Chapter%20%206%20Data%20Sets/CH06PR18.txtarrow_forward
- Using R languagearrow_forwardHow can I type the Java OOP code by using JOptionPane with this following code below: public static void sellCruiseTicket(Cruise[] allCruises) { //Type the code here }arrow_forwardDraw a system/level-0 diagram for this scenario: You are developing a new customer relationship management system for the BEC store, which rents out movies to customers. Customers will provide comments on new products, and request rental extensions and new products, each of which will be stored into the system and used by the manager for purchasing movies, extra copies, etc. Each month, one employee of BEC will select their favorite movie pick of that week, which will be stored in the system. The actual inventory information will be stored in the Entertainment Tracker system, and would be retrieved by this new system as and when necessary. Example of what a level-0 diagram looks like is attached.arrow_forward
- What is the value of performing exploratory data analysis in designing data visualizations? What are some examples?arrow_forwardDraw a level-0 diagram for this scenario: You are developing a new customer relationship management system for the BEC store, which rents out movies to customers. Customers will provide comments on new products, and request rental extensions and new products, each of which will be stored into the system and used by the manager for purchasing movies, extra copies, etc. Each month, one employee of BEC will select their favorite movie pick of that week, which will be stored in the system. The actual inventory information will be stored in the Entertainment Tracker system, and would be retrieved by this new system as and when necessary.arrow_forwardDraw a context diagram for this scenario: You are developing a new customer relationship Management system for the BEC store, which rents out movies to customers. Customers will provide comments on new products, and request rental extensions and new products, each of which will be stored into the system and used by the manager for purchasing movies, extra copies, etc. Each month, one employee of BEC will select their favorite movie pick of that week, which will be stored in. the system. The actual inventory information will be stored in the Entertainment Tracker system, and would be retrieved by this new system as and when necessary.arrow_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