Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 12, Problem 14PP
Program Plan Intro
Remove duplicates names from file
- Import required package.
- Define “InvitationList” class.
- Define main function.
- Create “HashSet” for names.
- Declare required variables.
- Assign scanner object to “null”.
- Inside the “try” block,
- Define “namesList” file using “FileInputStream”.
- Check condition using “while” loop.
- Read name from file.
- Check if the name is in the set or not. If the name is in the set already, then ignore it. If the name is not contains in the set, then add the given name to “names_set”.
- Close the file.
- Display statement.
- Display all names in set using “for” loop
- Catch the exception using “catch” keyword.
- Display given error and exit the program.
- Define main function.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Java Programming
This week's project involves a text file with that holds all of the novel Don Quixote*, by Miguel Cervantes. The text file has been heavily processed. It contains only lowercase letters, spaces, and new lines. That is a good format for counting words. Write code that reads through the text file one word at a time using a Scanner, and the next() method.
Put the words into a HashMap, where the words are used as keys, and the values are Integers used to keep track of how many times the words occur in the text.
If the text was "one fish two fish red fish blue fish one two three" then the HashMap would look like this:
key value
"one".... 2
"fish"... 4
"two".... 2
"red".... 1
"blue"... 1
"three".. 1
Once you have created such a HashMap for the whole of the text you can write logic that prints out the answers to these questions:
How many times does each of…
JAVA
Create a new class HashMapManipulation with a main method.
Import the necessary classes from the java.util package, including the HashMap class.
Create a HashMap object, named mapand use the put() method to add key-value pairs to the map. The keys are strings "A", "B", and "C", and the values are integers 1, 2, and 3 respectively.
Use the size() method to print the size of the map.
Use a for loop to print the key-value pairs in the map. The loop should iterate over the entries in the map using the entrySet() method, which will return a set of Map.Entry objects representing the key-value pairs in the map. The key and value of each entry are printed using the getKey() and getValue() methods, respectively.
Use theget() method to get the value of key "A", and assigns it to a variable value. The value is then printed.
Use the put() method to add a new key-value pair to the map. The key is "D" and the value is 4. The map is then printed again, to show the added key-value…
How do I write this java program in hashmap?
The program should create charts showing the consistency of the two judges. The rows represent the scores given by Dr. Stansifer and the columns represent the scores given by Dr. Shoaff. Suppose the maximum score is 3 the judges give the following scores.
Manatee ID
Dr. Shoaff's Score
Dr. Stansifier's Score
1
0
0
23
0
3
14
0
0
5
3
0
19
2
3
18
1
1
12
3
2
204
1
1
6
0
0
25
3
3
The consistency chart resulting from these scores are:
0
1
2
3
0
3
0
0
1
1
0
2
0
0
2
0
0
0
1
3
1
0
1
1
The "3" in the upper left hand corner indicates that there were 3 manatees that Dr Shoaff and Dr Stansifer gave a 0 score. (namely manatee 1, 14, 6). The 1 in row 0, column 1 indicates there was 1 manatee that Dr. Shoaff scored a 0 while Dr Stansifer scores a 3 (namely manatee 23). Ideally the only non-zero entries in the table would be along the diagonal indicating perfect consistency. Your program should take a group of scores…
Chapter 12 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 12.1 - Suppose aList is an object of the class...Ch. 12.1 - Prob. 2STQCh. 12.1 - Prob. 3STQCh. 12.1 - Prob. 4STQCh. 12.1 - Can you use the method add to insert an element at...Ch. 12.1 - Prob. 6STQCh. 12.1 - Prob. 7STQCh. 12.1 - If you create a list using the statement...Ch. 12.1 - Prob. 9STQCh. 12.1 - Prob. 11STQ
Ch. 12.1 - Prob. 12STQCh. 12.2 - Prob. 13STQCh. 12.2 - Prob. 14STQCh. 12.2 - Prob. 15STQCh. 12.2 - Prob. 16STQCh. 12.3 - Prob. 17STQCh. 12.3 - Prob. 18STQCh. 12.3 - Prob. 19STQCh. 12.3 - Write a definition of a method isEmpty for the...Ch. 12.3 - Prob. 21STQCh. 12.3 - Prob. 22STQCh. 12.3 - Prob. 23STQCh. 12.3 - Prob. 24STQCh. 12.3 - Redefine the method getDataAtCurrent in...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.4 - Revise the definition of the class ListNode in...Ch. 12.4 - Prob. 30STQCh. 12 - Repeat Exercise 2 in Chapter 7, but use an...Ch. 12 - Prob. 2ECh. 12 - Prob. 3ECh. 12 - Repeat Exercises 6 and 7 in Chapter 7, but use an...Ch. 12 - Write a static method removeDuplicates...Ch. 12 - Write a static method...Ch. 12 - Write a program that will read sentences from a...Ch. 12 - Repeat Exercise 12 in Chapter 7, but use an...Ch. 12 - Write a program that will read a text file that...Ch. 12 - Revise the class StringLinkedList in Listing 12.5...Ch. 12 - Prob. 12ECh. 12 - Write some code that will use an iterator to...Ch. 12 - Prob. 14ECh. 12 - Write some code that will use an iterator to...Ch. 12 - Prob. 17ECh. 12 - Revise the method selectionSort within the class...Ch. 12 - Repeat the previous practice program, but instead...Ch. 12 - Repeat Practice Program 1, but instead write a...Ch. 12 - Write a program that allows the user to enter an...Ch. 12 - Write a program that uses a HashMap to compute a...Ch. 12 - Write a program that creates Pet objects from data...Ch. 12 - Repeat the previous programming project, but sort...Ch. 12 - Repeat the previous programming project, but read...Ch. 12 - Prob. 9PPCh. 12 - Prob. 10PPCh. 12 - Prob. 11PPCh. 12 - Prob. 12PPCh. 12 - Prob. 13PPCh. 12 - Prob. 14PPCh. 12 - Prob. 15PP
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
- This problem is based on Hashing. Please use Python and do not make it overly lengthy and complicated making it difficult to understand. PLEASE USE PYTHON and do not make the code too difficult to understand. Keep it simple. Thanks Given an array containing Strings, you need to write a code to store them in a hashtable. Assume that the Strings contain a combination of capital letters and numbers, and the String array will contain no more than 9 values. (total number of consonants*24 + summation of the digits) %9. In case of a collision, use linear probing.For a String “ST1E89B8A32”, it’s hash function will produce the value=(3*24+(1+8+9+8+3+2))%9=4, hence it will be stored in index 4 of the hash table.arrow_forwardOne use of a hash table is to implement a set data type. You will implement the methods addElement, find, toString, resize, and the MySetIterator inner class in the class MySet. MySet uses a separate chaining hash table to implement a set of integers. To get started, import the starter file, MySet.java into the hashset package you create in a new Java Project. Please do not change any of the method signatures in either class. Implement the methods described below. You are free to test your code however you prefer. Below is method Signature class: package hashset; import java.util.Iterator; public class MySet { // implements a set using a separate chaining hash table private class Node { private Integer element; private Node next; private Node(Integer e, Node n) { element = e; next = n; } } private Node table[]; //an array of linked list private int tableSize; //current number of lists in the table private int…arrow_forwardOne use of a hash table is to implement a set data type. You will implement the methods addElement, find, toString, resize, and the MySetIterator inner class in the class MySet. MySet uses a separate chaining hash table to implement a set of integers. To get started, import the starter file, MySet.java into the hashset package you create in a new Java Project. Please do not change any of the method signatures in either class. Implement the methods described below. You are free to test your code however you prefer. For additional programming practice, you can implement the union, intersect, difference methods (see the comments in the code for the desired functionality). private void resize()This method "doubles" the table size and reinserts the values stored in the current table. The table size should remain prime. private boolean find(Integer e)This method returns true if the integer e is in the set and false otherwise. private void addElement(Integer e)If e is not in the set, add e to…arrow_forward
- Write a program to produce the first 100 Fibonacci numbers. A Fibonacci number is one that is the product of the prior two generated numbers. The sequence is seeded with the values of 0 and 1, so that the sequence starts off as 01 123. Fibonacci numbers are used in computing hash table locations for file management systems.arrow_forwardIn Java please. Add comments as well. Thank you!arrow_forwardImplement a city database using ordered lists by using java. Each database record contains the name of the city (a string of arbitrary length) and the coordinates of the city expressed as integer x and y coordinates. Your database should allow records to be inserted, deleted by name, and searched by name. Another operation that should be supported is to print all records within a given distance of a specified point/coordinate. The order of cities should be alphabetically by city name. Implement the database using both: an arraybased list implementation, and a circular single linked list implementation.Use may the following node, SLL implementations to implement an ordered circular single linked listarrow_forward
- Create a Java program. You have a list of Student ID's followed by the course number(separated by aa space) that the student is enrolled in. The listing is in no particular order. For eg. is student 1 is in CS100 and CS200 while student 2 is in CS105 and MATH210 then the list may look like this: 1 CS100 2 MATH210 2 CS105 1 CS200 Write a program that reads data in this format from the console. If the ID is -1 then stop inputting data. Use the HashMap class to map from an Integer(Student ID) to an ArrayList of type String that holds each class that the student is enrolled in. The declaration should look like this: HashMap<Integer, ArrayList<String>> students = new HashMap<Integer, ArrayList<String>>(); After all data is input, iterate through the map and output the student ID and all classes stored in the vector for that student. The result should be a list of classes organized by student id.arrow_forward: Imagine you are reading in a stream of integers. Periodically, you wish to be able to look up the rank of a number x (the number of values less than or equal to x). Implement the data structures and algorithms to support these operations. That is, implement the method track(int x), which is called when each number is generated, and the method getRankOfNumber(int x), which returns the number of values less than or equal to x (not including x itself). EXAMPLE Stream (in order of appearance): 5, 1, 4, 4, 5, 9, 7, 13, 3 getRank Of Number (1) = 0 getRankOf Number (3) = 1 getRankOfNumber (4) = 3arrow_forwardImagine you are reading in a stream of integers. Periodically, you wishto be able to look up the rank of a number x (the number of values less than or equal to x). Implement the data structures and algorithms to support these operations. That is, implement the method track(int x), which is called when each number is generated, and the method getRankOfNumber(int x), which returns the number of values less than or equal to x (not including x itself).EXAMPLEStream(in order of appearance):5, 1, 4, 4, 5, 9, 7, 13, 3getRankOfNumber(l) 0getRankOfNumber(3) 1getRankOfNumber(4) 3arrow_forward
- I ran the code and there are lots of errors in the code. Attached are images of the errors. Make sure to fix those errors and there must be no error in the code at all.arrow_forwardWrite a program that uses an ArrayList of parameter type Contact to store a database of contacts. The Contact class should store the contact's first and last name, phone number, and email address. Add appropriate accessor and mutator methods. Your database program should present a menu that allows the user add a contact, display all contacts, search for a specific contact and display it, or search for a specific contact and give the user the option to delete it. The searches should find any contact where an instance variable contains a target search string. For example, if "elmore" is the search target then any contact where the first name, last name, phone number, or email address contains "elmore" should be returned for display or deletion. Use a "for each" loop to iterate through the ArrayList.arrow_forwardImplement a “To Do” list. Tasks have a priority between 1 and 9, and a description (which you can come up with on your own, say, “wash dishes”). The program is going to prompt the user to enter the tasks by running the method add_priority_description, the program adds a new task and prints the current list with priority 1 tasks on the top, and priority 9 tasks at the bottom. The program will continue to ask the user if they want to add another tasks, and repeat the add_priority_description method, or enters Q to run the quit method to quit the program. Sample output (not limited to) 1. Study for the final 1. Take the final 2. Watch Justice League with friends 3. Play ball 9. Wash Dishes 9. Clean room. There is a possibility of two tasks having the same priority. If so, the last task that was entered gets to be printed first. Use HEAP in your solution.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