Question

*USE JAVA In this project you will create program that calculate the number of times every...

*USE JAVA

In this project you will create program that calculate the number of times every word appears in a given text file. Your program will take in the name of the file as well as the number of threads to create to speed up the process. The numbers of threads must be greater than 0. The output will be saved into a file in alphabetical order.

Besides creating the program itself, you are to run experiments to show how the use of threads can help or hurt your programs efficiency. This means you will produce a report (around a page) detailing your algorithm, your experiment, and the data you collected. Be sure to include at least one graph of your runtime based on different thread counts.

As you did in the previous homework, please submit your code, your report, and a Readme to allow me to run your project as well as replicate your experiments.

*USE JAVA

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

As per the problem statement, In order to find the number of times every word appears in the text file, I'm using multi threaded envirnoment to solve this .

As you mentioned in the second problem statement, if file size was bug enough to handle in such case multi threaded race condition will . works fine with provided code and works efficiently.

Please find the pseudo code below:

public class WrodCountImpl

{

   public static void main(String args[])

   {

for (String filename : args)

{

   Runnable tester = new WordCount(filename);

   Thread t = new Thread(tester);

   t.start();

}

   }

}

public class WordCount implements Runnable

{

   public WordCount(String filename)

   {

this.filename = filename;

   }

   public void run()

   {

String wordname = scan.nextLine();

int count = 0;

try (LineNumberReader r = new LineNumberReader(new FileReader(filename))) {

String line;

while ((line = r.readLine()) != null) {

for (String element : line.split(" ")) {

if (element.equalsIgnoreCase(wordname)) {

count++;

System.out.println("Word found at line " + r.getLineNumber());

}

}

}

}

System.out.println("The word " + wordname + " appears " + count + " times.");

   }

   private String filename;

}

As question was lengthy , i answered the business logic.

Please reach me out , if any doubts  

Add a comment
Know the answer?
Add Answer to:
*USE JAVA In this project you will create program that calculate the number of times every...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA Program! Write a program that makes use of threading. You will have one thread count how many times a second has p...

    JAVA Program! Write a program that makes use of threading. You will have one thread count how many times a second has passed and the second thread will count how many times 3 seconds has passed This will occur in an infinite loop and the counts will be printed to the screen. Indent the count of one of the threads for easier viewing Write a program that makes use of threading. You will have one thread count how many times...

  • Description: Overview: You will write a program (says wordcountfreq.c) to find out the number of words and how many times each word appears (i.e., the frequency) in multiple text files. Specifically,...

    Description: Overview: You will write a program (says wordcountfreq.c) to find out the number of words and how many times each word appears (i.e., the frequency) in multiple text files. Specifically, the program will first determine the number of files to be processed. Then, the program will createmultiple threads where each thread is responsible for one file to count the number of words appeared in the file and report the number of time each word appears in a global linked-list....

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the ...

    Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the merge sort algorithm. The basic steps of merge sort are: 1) divide a collection of items into two lists of equal size, 2) use merge sort to separately sort each of the two lists, and 3) combine the two sorted lists into one sorted list. Of course, if the collection of items is just asingle item then merge sort doesn’t need to perform the three steps,...

  • kindly make a java threaded program main class will accept n number and produce user inputed...

    kindly make a java threaded program main class will accept n number and produce user inputed array of n elements make 3 child threads(class) out of one main thread(class) must use thread.sleep and thread synchronization one thread create max of array elements one will min of array elements one will provide average of array elements then display of array will occur

  • Description In this homework, you are asked to implement a multithreaded program that will allow ...

    Description In this homework, you are asked to implement a multithreaded program that will allow us to measure the performance (i.e, CPU utilization, Throughput, Turnaround time, and Waiting time in Ready Queue) of the four basic CPU scheduling algorithms (namely, FIFO, SJE PR, and RR). Your program will be emulating/simulating the processes whose priority, sequence of CPU burst time(ms) and I'O burst time(ms) will be given in an input file. Assume that all scheduling algorithms except RR will be non-preemptive,...

  • Create a New Java Project called YourLastNameUpperCase. Write a program that asks the user for the...

    Create a New Java Project called YourLastNameUpperCase. Write a program that asks the user for the names of two files. The first file should be opened for reading and the second file should be opened for writing. The program should read the contents of the first file, change all characters to uppercase, and store the results in the second file. The second file will be a copy of the first file, except that all the characters will be uppercase. Use...

  • Understand the Application For this lab you will create a basic application programming interface (API) for...

    Understand the Application For this lab you will create a basic application programming interface (API) for spawning multiple threads in a program using Python3's threading module. The Program Spec Write a program that creates a minimum of two threads with different target functions. Each thread will perform the work of each function. Each function will compute a task (described below) and print out a result. Implementation Details Write a program that creates a minimum of two threads using Python's threading...

  • multithreaded sorting program in Java

    Write a multithreaded sorting program that works as follows: A list of integers is divided into Four smaller lists of equal size. Four separate threads (which we will term sorting threads) sort each sub-list using a sorting algorithm of your choice. (You may use any built in sorting function). A Fifth thread then merges the Four sub-lists — a merging thread — which merges the Four sub-lists into a single sorted list. Because global data are shared cross all threads,...

  • Code in C++ Modify “Producer and Consumer Problem” from lecture note so that it can use...

    Code in C++ Modify “Producer and Consumer Problem” from lecture note so that it can use all buffer space, not “buffersize – 1” as in the lecture note. This program should work as follows: 1.The user will run the program and will enter two numbers on the command line. Those numbers will be used for buffersize and counter limit. 2. The program will then create a separate threads, producer and consumer thread. 3. Producer thread generates a random number through...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT