Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
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.

Blurred answer
Students 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…
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning