Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
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
In JAVA, use a HashMap to count and store the frequency counts for all the words from a large text document. Using file util, please. Then, display the contents of this HashMap with words and frequency count.
Next, please create a set view of the Map and store the contents in an array. Sort this array based on key value and display it.
Finally, sort the array in decreasing order by frequency and display it as well. Please label your explanation in the code Thank you
In JAVA, use a HashMap to count and store the frequency counts for all the words from a large text document. Then, display the contents of this HashMap with given words and their frequency in the document.
Next, please create a set view of the Map and store the contents in an array. Sort this array based on key value and display it.
Finally, sort the array in decreasing order by frequency and display it.
Write a program that uses a HashMap to compute a histogram of positivenumbers entered by the user. The HashMap’s key should be the numberthat is entered, and the value should be a counter of the number of timesthe key has been entered so far. Use −1 as a sentinel value to signal theend of user input. For example, if the user inputs:512355321-1then the program should output the following (not necessarily in this order):The number 3 occurs 2 times.The number 5 occurs 3 times.The number 12 occurs 1 times.The number 21 occurs 1 times.
Chapter 12 Solutions
Java: An Introduction to Problem Solving and Programming (8th 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.5 - What is the purpose of the FXML file?Ch. 12.5 - Prob. 32STQCh. 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
- Implement a city database using ordered lists. 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: an array- based list implementation. By using JAVA.arrow_forwardThis is Java Move the Nth element to the back of the Queue. Write the Java program that reads 5 integers in from the keyboard (user input) and loads the integers into a Queue. Add a method ‘moveNth(queue, locationToMove );’ that accepts a queue and an integer, as the two parameters. Your ‘moveNth’ method will find the ‘locationToMove’ and “move that value to the end of the Queue.” For example: Method Call – moveNth(queue, 3); Queue before Call: 1 2 3 4 5 Queue after call: 1 2 4 5 3 Your code can only use the queue data structure (and if wanted, an integer variable to store each integer read from the user’s input). Sample method calls in main() loadQueue(queue); displayQueue(queue); moveNth(queue, 4); // your code should work for any locationToMove displayQueue(queue); This is java. Thanks.arrow_forwardFor this lab, you will need to use the files BagInterface.java, Item.java, and LinkedBag.java.arrow_forward
- Write a python program that scans in a large number of tweets from a file, and prints the top 5 hashtags. Approach Parse each word in the file Find a way to isolate the hashtags from the rest of the tweet Compute the frequency of each unique hashtag. Find the top 5 hashtags. Caveats 1. Because this is public dataset, there are many tweets that use special characters that may cause issues during reading in your file. To avoid this, explicitly specify the encoding mode in open when reading in the file. with open('twitter_data.txt', 'r', encoding='utf8') as f: 2. When parsing hashtags be sure to change everything to lowercase. There are cases in the file where two hashtags are the same but differ in case. 3. There is no standard way of sorting a dictionary based on the values. Python gives you access to a sorted function where you can pass in a collection and also specify a comparator which outlines how you want to sort the values. This can be done with a one line lambda function.arrow_forwardWrite the programme with Java Programming lang.arrow_forwardWrite a Java program that asks the user to enter items until the user chooses to stop, stores them into links (nodes), and chains the links together into a linked list. You will need to make the following changes: Your linked list should store information about Customers' Transactions that contain three fields: customer name (string), customer number (int), and transaction description (string). Instead of putting all of your code inside the main source code file, you should create the following functions: o addToStart(Item x) o addToEnd(Itemn x) o insertAt(Item x, int n) o remove(int customer number) o reverse() o printList() • Instead of simply asking the user if they want to add a new link, your main program should offer the user a menu of options: o Add a new link to the end o Add a new link to the beginning o Insert an element at index n into the list. 0 Remove a link from the list o Reverse the list o print out the entire list o Quit the programarrow_forward
- Implement 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_forwardImplement the Round Robin Scheduler as described in attached notes “Round Robin SchedulerExample.pdf” using queue (you can use either ArrayQueue or LinkedQueue), based on theprovided starter Python code “robin_scheduler.py”. In the starter file, three tasks have alreadybeen set in a tasks list according to the example in the attached document. You are only asked tocomplete the method “scheduling”. Once you finish your code based on the starter code and runit, the output should be same as bellow. You should test your code using more examples.arrow_forwardWrite a program in which the four password breaking cases that we discussed in the lecture are implemented. The password file should contain 6-digit numbers only (from 000000 to 999999) and assume that the attacker knows that. You can use any pre-implemented open-source hash algorithm such as MD5 or SHA-256. I encourage you to use MD5 since it is faster than SHA-256. Your dictionary should contain 21ºpasswords. Your system has 2° users.arrow_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_forwardMake a telephone lookup program. Read a data set of 1,000 names and telephone numbers from a file that contains the numbers in random order. Handle lookups by name and also reverse lookups by phone number. Use a binary search for both lookups. This assignment needs a resource class and a driver class. The resource class and the driver class will be in two separate files. The resource class will contain all of the methods and the driver class only needs to call the methods. The driver class needs to have only 5 lines of code. The code needs to be written in Java. Please help me with exactly what I asked for help.arrow_forwardyou will create a spell checker. The program will take three command line arguments: number of words in the dictionary, a dictionary file name, and a text file name. The program will first create a hash table. The number buckets of the hash table should be about twice the number of words in the dictionary. Then, it will read the dictionary from the file, insert the words into the hash table, and report collision statistics. After reading the dictionary, the spelling checker will read a list of words from a text file. Each word will be looked up in the dictionary. If it is incorrect, it will be written to the standard output together with a list of suggested corrections. The algorithm for generating corrections is given below. Hash Table The hash table programs, QuadraticProbing.h and QuadraticProbing.cpp, are posted on Canvas. The programs use quadratic probing to deal with collisions. You should carefully study these programs and make some changes to collect the required statistics.…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