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
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.
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.
We know that the first file name is stored at index zero in the ArrayList, and the list stores the file names as strings, so could we write the body of listAllFiles along the following lines? System.out.println(files.get(0)); System.out.println(files.get(1)); System.out.println(files.get(2)); etc. How many println statements would be required to complete the method?
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
- Write a program that reads a text file and creates an alphabetical index of words and in which lines of this original example. The file name is given as an argument to main (). Ignore the small-capital (all lowercase: k,l,p) and punctuation. Solve with ternary tree using the TST.java class (https://algs4.cs.princeton.edu/52trie/TST.java.html). An execution snapshot is then given. For the file: It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness It will appear Index of file: exercise.txt age 3-4 best 1 foolishness 4 it 1-2-3-4 of 1-2-3-4 the 1-2-3-4 times 1-2 was 1-2-3-4 wisdom 3 worst 2arrow_forwardImplement the Plates class buildMap function so that it populates the HashMap with the state abbreviations as keys and the counts of how many each appear in the file as values. Sometimes, the parking attendant will add special notation to help her remember something about a specific entry. There are just non alphabetic characters that she adds to the state - your program should ignore these characters so that an entry like NY* still counts toward the NY plate count. She is also very inconsistent with how she enters the plates. Sometimes she uses upper case, sometimes lowercase, and sometimes she even uses a mix. Be sure to account for this in your program. Only add information for plates in New England (Maine, New Hampshire, Vermont, Massachusetts, Rhode Island, and Connecticut). Plates.java import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; public class Plates { private Map<String, Integer> plateMap;…arrow_forwardUsing eclipse, write a Console Java program that inserts 25 random integers in the range of 0 to 100 into a Linked List. (Use SecureRandom class from java.security package.SecureRandom rand = new SecureRandom(); - creates the random number objectrand.nextInt(100) - generates random integers in the 0 to 100 range)Using a ListItreator output the contents of the LinkedList in the original order. Using a ListItreator output the contents of the LinkedList in the reverse order.arrow_forward
- Write a static method named "compareLines" that accepts one parameter (a Scanner attached to an input file). Your method should compare each neighboring pair of lines (the 1st and 2nd lines, then the 3rd and 4th lines, and so on) looking for indexes in both strings that contain vowels [a, e, i, o, u, y, A, E, I, O, U, Y] and should output the index where both strings contained a vowel. For example, in the strings "hello" and "bully, the characters at indexes 1 and 4 match since both contain vowels at that index. For each pair of lines, your method should print output showing the character indexes that match, separated by spaces in the format shown below. If no characters match, print "none" instead as shown below. For example, suppose the input file contains the following text. (Line numbers and character indexes are shown around the input and matching characters are shown in bold, but these markings do not appear in the actual file.) 0123456789012345678901234567890123456789 (String…arrow_forwardWrite a static method named "compareLines" that accepts one parameter (a Scanner attached to an input file). Your method should compare each neighboring pair of lines (the 1st and 2nd lines, then the 3rd and 4th lines, and so on) looking for indexes in both strings that contain vowels [a, e, i, o, u, y, A, E, I, O, U, Y] and should output the index where both strings contained a vowel. For example, in the strings "hello" and "bully, the characters at indexes 1 and 4 match since both contain vowels at that index. For each pair of lines, your method should print output showing the character indexes that match, separated by spaces in the format shown below. If no characters match, print "none" instead as shown below. For example, suppose the input file contains the following text. (Line numbers and character indexes are shown around the input and matching characters are shown in bold, but these markings do not appear in the actual file.) 0123456789012345678901234567890123456789 (String…arrow_forwardHow 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…arrow_forward
- How do I write a java program to count the number of times each finger presses one of the keys using hashSet? When playing music on an Eb Alto Saxophone, the fingers press some keys more than others. For simplicity assume that the music is composed of only 1414 different notes. They are: C D E F G A B in one octave and C D E F G A B in a higher octave. We use c,d,e,f,g,a,b,C,D,E,F,G,A,B to represent them. The fingers typically used for each note are: c: finger 22-44, 77-1010 d: finger 22-44, 77-99 e: finger 22-44, 77, 88 f: finger 22-44, 77 g: finger 22-44 a: finger 22, 33 b: finger 22 C: finger 33 D: finger 11-44, 77-99 E: finger 11-44, 77, 88 F: finger 11-44, 77 G: finger 11-44 A: finger 11-33 B: finger 11-22 (Note that every finger is controlling a specific key, different fingers are controlling different keys.) A finger presses a key if it is needed in a note, and if that same finger is not used in the note previously played. Naturally, every key…arrow_forwardIn this task, two hash tables should should be implemented. You can follow the followinginstructions:- In class HashTable implement a hash table and consider the following:(i) Keys are integers (therefore also negative!) and should be stored in the tableint[] data.(ii) As a hash function take h(x) = (x · 701) mod 2000. The size of the table istherefore 2000. Be careful when computing the index of a negative key. Forexample, the index of the key x = −10 ish(−10) = (−7010) mod 2000 = (2000(−4) + 990) mod 2000 = 990.Hence, indices should be non-negative integers between 0 and 1999!(iii) Implement insert, which takes an integer and inserts it into a table. Themethod returns true, if the insertion is successful. If an element is already inthe table, the function insert should return false.(iv) Implement search, which takes an integer and finds it in the table. The methodreturns true, if the search is successful and false otherwise.(v) Implement delete, which takes an integer and deletes it…arrow_forwardYou are a cyber investigator, your task is to write a python program that can read file signatures from a file and save them into a list. Each file signature is an element of your list. Then, try to find out if there is a JPG file in there. If there is a JPG file, print out a True on screen. (File Signature for JPG file is: FF D8 FF DB) The input file is: FSCS360_Midterm_Exam_Part2.txtarrow_forward
- One common use of a hash table is to build a glossary, or dictionary, of terms.In this section, we demonstrate one way to use a hash table for just such ause—a computer terms glossary.The program works by first reading in a set of terms and definitions from atext file. This process is coded in the BuildGlossary subroutine. The structureof the text file is: word,definition, with the comma being the delimiter betweena word and the definition. Each word in this glossary is a single word, but theglossary could easily work with phrases instead. That’s why a comma is usedas the delimiter, rather than a space. Also, this structure allows us to use theword as the key, which is the proper way to build this hash table.Another subroutine, DisplayWords, displays the words in a list box so theuser can pick one to get a definition. Since the words are the keys, we can usethe Keys method to return just the words from the hash table. The user canthen see which words have definitions.To retrieve a…arrow_forwardIn 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 youarrow_forwardWrite a Python program that takes a single string as an input from the user where few numbers are separated by commas. Now, make a list with the numbers of the given string.Then your task is to remove multiple occurences of any number and then finally print the list without any duplicate values. Hint (1): For obtaining the numbers from the string, use split(). For cleaning the data, use strip(). Hint (2): You may create a third list to store the results. You can use membership operators (in, not in) to make sure no duplicates are added. =================================================================== Sample Input 1:0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4 Sample Output 1:Given numbers in list: [0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]List without any dupliacte values: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] =================================================================== Sample Input 2:7, 7, 7, 1, 0, 3, 3, 55, 9 Sample Output 2:Given numbers in…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