Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 21, Problem 21.8PE
Program Plan Intro
CountOccurenceofWordsfromFile.Java
Program Plan:
- Include a class named “DisplayFrequency”.
- Import BufferedReader.
- Import file from io package.
- Import FileReader from io package.
- Import exception package.
- Import java util package.
- Declare the main() function.
- Declare a scanner for user input.
- Prompt the user to input file path.
- Check if file is present or not.
- Create a word array.
- Inside a try block declare “BufferedReader” and create a new String buffer.
- Split the words using toString() method and append the strings.
- Catch block is declared to handle the exception.
- To hold words as key and count as value, a TreeMap is created.
- Use split method to split words.
- Convert word to lowercase.
- Check if length of key is greater than 0.
- Check if the map contains the key.
- Insert key into map.
- Get the key.
- Update the key value and store the updated value.
- Display key and value for each entry.
- Create a new text file “file”.
- Add words into the text file.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(Class Average: Reading Student Records from a CSV File) Use Python
Use the csv module to read the grades.csv file from the previous exercise (exercise 9.3).
Display the data in tabular format, including an additional column showing each student’s average to the right of that student’s three exam grades and an additional row showing the class average on each exam below that exam’s column.
This is exercise 9.3
# Importing csv moduleimport csv# empty list to store datadata = []columns = ["firstname", "lastname", "grade1", "grade2", "grade3"]filename = "grades.csv"for i in range(3):firstname = input("Enter First Name : ")lastname = input("Enter Last Name : ")grade1 = float(input("Enter Grade 1 : "))grade2 = float(input("Enter Grade 2 : "))grade3 = float(input("Enter Grade 3 : "))data.append([firstname, lastname, grade1, grade2, grade3])print()# write data and columns as csv filewith open(filename, 'w') as csvfile:# creating a csv writer objectcsvwriter = csv.writer(csvfile)# writing the…
(Intro to Java)
Explain the answers to the below questions. include a written answer to the question using step-by-step explanation
3. Write 5-6 lines of code to open a PrintWriter and write out the contents of the plants array into a text file named plants.txt
1. Quit (exit the program)2. Add (to the ArrayList) all the marks information about a coursework or research student byreading it from another text file and determine the student’s overall mark and grade.You will need to consider how to deal with the different assessment components for thecoursework and research students. You may use two different text files, one for courseworkstudents and another for research students. The program should read the correct text file forthis purpose.3. Given student number (ID), remove the specified student and relevant information from theArrayList. It is always good to ask the user to confirm again before removing the record. Forconfirmation, output the student number (ID) and the name to the user.4. Output from the ArrayList the details (all information including the overall mark and thegrade) of all students currently held in the ArrayList.5. Compute and output the overall mark and grade for coursework or research students6. Determine and display how…
Chapter 21 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 21.2 - Prob. 21.2.1CPCh. 21.2 - Prob. 21.2.2CPCh. 21.2 - Prob. 21.2.3CPCh. 21.2 - Prob. 21.2.4CPCh. 21.2 - Prob. 21.2.5CPCh. 21.2 - Suppose set1 is a set that contains the strings...Ch. 21.2 - Prob. 21.2.7CPCh. 21.2 - Prob. 21.2.8CPCh. 21.2 - What will the output be if lines 67 in Listing...Ch. 21.2 - Prob. 21.2.10CP
Ch. 21.3 - Prob. 21.3.1CPCh. 21.3 - Suppose you need to write a program that stores...Ch. 21.3 - Suppose you need to write a program that stores...Ch. 21.3 - Suppose you need to write a program that stores a...Ch. 21.3 - Prob. 21.3.5CPCh. 21.3 - Prob. 21.3.6CPCh. 21.4 - Prob. 21.4.1CPCh. 21.4 - Prob. 21.4.2CPCh. 21.5 - Prob. 21.5.1CPCh. 21.5 - Prob. 21.5.2CPCh. 21.5 - Prob. 21.5.3CPCh. 21.6 - Prob. 21.6.1CPCh. 21.6 - Prob. 21.6.2CPCh. 21.6 - Prob. 21.6.3CPCh. 21.6 - Prob. 21.6.4CPCh. 21.7 - Prob. 21.7.1CPCh. 21.7 - Prob. 21.7.2CPCh. 21 - Prob. 21.1PECh. 21 - (Display nonduplicate words in ascending order)...Ch. 21 - Prob. 21.3PECh. 21 - (Count consonants and vowels) Write a program that...Ch. 21 - Prob. 21.6PECh. 21 - (Revise Listing 21.9, CountOccurrenceOfWords.java)...Ch. 21 - Prob. 21.8PECh. 21 - Prob. 21.9PE
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 is for devc++ version 5.11) Create a text file with following data to test your code. Please use array of structure and try to use functions and pass array of structures to functions. Read the following data from this text file: Johnson 85 83 77 91 76Aniston 80 90 95 93 48Cooper 78 81 11 90 73Gupta 92 83 30 69 87Blair 23 45 96 38 59Clark 60 85 45 39 67Kennedy 77 31 52 74 83Bronson 93 94 89 77 97Sunny 79 85 28 93 82Smith 85 72 49 75 63 LOOK AT PICTURESarrow_forwardDesign void printStart(char *str, char ch). We know that str contains only uppercase words and Spaces, and the first and last characters are not Spaces, and there is only one space between two adjacent words. Ask to print all words in str beginning with the capital letter ch, separated by Spaces, on the screen. (please use c++)arrow_forwardNeed help and I am allowed to help.arrow_forward
- Exercise 1. (Spell Checker) Write a program spell_checker.py that accepts words from standard input; looks up each word in the file data/misspellings.txt that maps misspelled words to their correct spellings; and if it exists (ie, is misspelled), writes the word to standard output along with the correct spelling. >- "/workspace/project6 $ python3 spell_checker.py Try nto to become a man of sucess but rather try to become man of value. * Albert Einstein nto -> not sucess -> success E spell.checker.py from instream import InStream from symboltable import SymbolTable import stdio # Entry point. def main (): # Set inStream to an input stream built from the file 'data/misspellings.txt'. # Set lines to the list of lines read from inStream. .. # Set misspellings to a new symbol table object. .. for in ...: # For each line (of the form 'misspelling correction ') in lines... # Set tokens to the list obtained by splitting line using the split () method from str. # Insert the pair tokens…arrow_forwardNOTE:- Please type this java code and need an output also, even explain how to work this code. (Also tell how to create the text file for this code if necessary please)arrow_forward15). (Remove text) Write a program that removes all the occurrences of a specified string from a text file. (For example, my Aunt went to buy Medicines while Sam and I play Soccer. Removes the string Sam from the file.) 1) You should create a file with this paragraph. 2) removes the string "John and" from the file. Note:- Please write a java code and also need an output for this program. (Also, let me know with what name file should be saved to get output)arrow_forward
- Hello, How can I store a whole book in a file in c language? I had some issues because the string is too long. here is the question: For this assignment I have uploaded a large text file that contains the entire book “Robinson Crusoe” byWilliam Defoe as file defoe-robinson-103.txt Consider the code shown below. It uses the fgets function.fgets is used to read (“get”) strings (“s”) from a file (“f”), hence the name “fgets”. It takes the following arguments:1. A pointer to an array large enough to store the string. In our case that is the char array calledbuffer of size MAX.2. The size of the array, in our case the symbolic constant MAX, set equal to 4000 in line 4.3. The file pointer of the file to read from, in our case bkPtr. Each call to fgets returns a string until the newline (“\n”) character or EOF is encountered. The codereads strings from the file defoe-robinson-103.txt in the while loop and prints them to screen.Implement this program and run it.arrow_forward(Use DevC++) 2. Student GradeWrite a program that reads a student name followed by five test scores. The program should output the student name, the five test scores, and the average test score. Output the average test score withtwo decimal places. The data to be read is stored in a file called test.txt. The output should be stored in a file calledtestavg.out. Input: A file containing the student name and the five test scores. A sample input is:Andrew Miller 87.50 89 65.75 37 98.50 Output: The student name, the five test scores, and the average of the five test scores, saved to a file. The program needs to read a student’s first and last name and five test scores. Therefore, you need two variables to store the student name and five variables to store the five test scores. To find theaverage, you must add the five test scores and then divide the sum by 5. Thus, you need a variable to store the average test score. Furthermore, because the input data is in a file, you need an…arrow_forward▼ Part A - The effect of an arithmetic shift on signed numbers Let's look at see what happens to signed numbers during a shift operation. As with most problems with number representations, errors can be intermittent. Sometimes the code will work as expected, and other times it will behave in a manner that seems to be totally arbitrary. Consider the following code fragment that makes use of the fact that shifting a value left by one place multiplies the number by 2. By passing in the number to be multiplied and the power of 2 to multiply it by (for example 4 = 22) the correct answer should be passed back from the function after the results are printed for the user to examine. signed int mult_2_to_n (signed int num, int n) { signed int result; result = num << n; printf("%d multiplied by 2^%d %d\n", num, n, result); return result; } Using a signed number as the manipulated integer may cause an error in some cases. Several approaches may be used to fix the problem. Which solutions below…arrow_forward
- - In C++ using Visual Studio - Seperate the files if there is any .cpp, .main or .h files. PART 1Read the contents of the text file and store them in a C++ data structure called std::map<string, int>This map is a collection of sorted <key, value> pairsIn this case, the keys are unique words found in the text file, and the values represent the number of times each word appearsFor example, since the word "cat" appears twice in the file, then map["cat"] = 2 PART 2Iterate through the map and print each key in the order they appearThis will give you a sorted list of unique wordsHere's the expected result: "a big cat does everything feeding goats helping injured juvenile kangaroos locating missing notorious objects playing quietly reading superb tales upvoting videos with xylophone yielding zebras" PART 3Iterate through the map again, this time printing each associated valueThe values represent how many times each word was found in the text filePay attention to the sequence of…arrow_forwardGood day/evening , C++ help needed. I am reading in two integers from a file. For example my input.txt file has the integers : “4–5” I am able to open the file and store the first value (4) into variable n but I can't store the second integer value (5) into variable m, I think the computer reads the dash as the next integer instead of the actual integer which is 5, how can I create a code that ignores the dash when searching for the integer in the input.txt? Thank youarrow_forwardModified Programming ). (Count vowels and consonants, file input, nested-loops, switch statement) Assume that letters A, E, I, O and U are the vowels. Write a program that reads strings from a text file, one line at a time, using a while-loop. You do the following operations within each loop: • Read one line from the input file and store it in a string; Count the number of vowels and consonants (using either while-loop or for-loop) in the file string. The while-loop will terminate when the end-of-file is reached. After the loop is finished, the program displays the total number of vowels and consonants in the text file. [A text file, named “ass4_Q6_input.txt", is provided as your testing input file.]arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning