Java Program /The Output attached by image
Overview
You should enter this task, ask the user for a word and then search for a file to see if that word is among the words in the file.
Task
This exercise comes with three text files named wordlist1.txt, wordlist2.txt and wordlist3.txt. These files contain a large amount of words in English. Each file contains more and more words. Each word in these files is on a separate line and the words contain only lowercase letters. Your task is to write a program that reads all these words from the file and checks if a keyword, which the user entered, is among the entered words. The program should also count the total number of words contained in the file used. The program should measure how long it takes to complete the search, ie how long it takes to read all the words and check if the keyword is among the words or not.
The program should start by asking the user for the word to be searched for. Then the words in the file should be counted and compared if the keyword exists or not. A printout should be made where the user is informed if the keyword existed or not, how long (in milliseconds) the search took and how many words the file contains in total.
As an argument to the program, the name of the file to be searched should be specified. If no argument is specified to the program, the file wordlist1.txt is to be used.
Tip
• The search does not have to take into account the exact matching of the keyword parts of words go well. If e.g. the user wants to search for only the letter a, it is enough that a word contains the letter a.
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter filename, inluding file ending> ");
String userInput = input.nextLine();
while (userInput.length() > 0) {
int dotIndex = userInput.lastIndexOf('.');
if (dotIndex == -1) {
System.out.println("Wrong filename format (missing .)\n");
}
else {
String suffix = userInput.substring(dotIndex + 1);
String filename = userInput.substring(0, dotIndex);
System.out.println("\nFilename: " + filename);
System.out.println("File ending: " + suffix + "\n");
}
System.out.print("Enter a new filename (only enter will exit)> ");
userInput = input.nextLine();
}
}
}
Step by stepSolved in 3 steps with 3 images
- debugarrow_forwardUse Java programarrow_forwardThe next three questions concern a program that opens a scores file provided by the user, reads it one line at a time, adds the scores as floating point numbers to a list scores, and then computes the average score. The example file scores.csv looks like this: Student Name, Test Score Jinyue, 98.5 Adesh, 97.4 Pinn, 99.1 Arindaam, 97.2 The first part of the program opens the file and reads just the first line into the variable header. # Open the Filename and ignore the first line filename= input("Enter filename:") open (filename) fhand = header = Fill in the blank to complete the program fragment:arrow_forward
- C++Create a program: Given a large text file with multiple strings, what would be the most efficient way to read the text file and count how many and which word appears the most repated word in a text file The text file's size is unknown. I add an image for input .arrow_forwardwrite java programarrow_forwardin python Write a program that will open a file .csv, read its contents and print them out. Your output should look like this: .csv (look the image) the file looks like these image First Last Age Wagejane Smith 21.00 21.50Jack Jones 20.00 19.50Edgar Martinez 22.00 22.75Zanab Sayegh 21.00 21.75arrow_forward
- In PYTHON Write the code that will open and read the data from a file named Numbers.csv and write it to a file named justAsNumbers.csvarrow_forwardWrite this as Java code Exercise #3: Write a program that finds all students who score the highest and lowest average marks of the first two homework in CS (). Your program should read the data from a file called "hw2.dat" and displays the output to another file called "hw2.out" and on the screen. The first line of the input file contains the number of students, N. The next N lines contain information about the students. Each data line contains student name and his/her marks. The output should display all student names, marks, and grades. In addition, you should output the highest and lowest marks and those who earned them along with the average and the grade of the class. If your input file contains: 20 Ali Al-Shikeli 80 81 Noora Al-Wardi 60 70 70 78 Aisha Al-Rabani Rugaya Al-Moqbali Karima Al-Rawas Manal Al-Siyabi 70 88 90 63 88 78 Khalsa Al-Sariri 68 89 Iman Al-Zadjali Farha Al-Waheibi Amel Mugabal 35 99 80 87 71 80 Munira Alabri 70 88 Amel Khamis Huda Al-Mukheini 91 83 83 83 Nawal…arrow_forwardcreateDatabaseOfProfiles(String filename) This method creates and populates the database array with the profiles from the input file (profile.txt) filename parameter. Each profile includes a persons' name and two DNA sequences. 1. Reads the number of profiles from the input file AND create the database array to hold that number profiles. 2. Reads the profiles from the input file. 3. For each person in the file 1. creates a Profile object with the information from file (see input file format below). 2. insert the newly created profile into the next position in the database array (instance variable).arrow_forward
- Java Your program must read a file called personin.txt. Each line of the file will be a person's name, the time they arrived at the professor's office, and the amount of time they want to meet with the professor. These entries will be sorted by the time the person arrived. Your program must then print out a schedule for the day, printing each person's arrival, and printing when each person goes in to meet with the professor. You need to print the events in order of the time they happen. In other words, your output will be sorted by the arrival times and the times the person goes into the professor's office. In your output you need to print out a schedule. In the schedule, new students go to the end of the line. Whenever the professor is free, the professor will either meet with the first person in line, or meet with the first person in line if nobody is waiting. Assume no two people arrive at the same time. You should solve this problem using a stack and a queue. You can only…arrow_forwardwordCountDistinct.py: Write a program that reads words from a file (filename given as a command-line argument) and prints the number of distinct words. Words that differ only in case should be considered to be equivalent.For example, using the input: If there's a problem yo I'll solve itCheck out the hook while my DJ revolves itIce ice baby The program should print 18.arrow_forwardPLEASE DONT COPY OFF OTHER POSTS CODE help with java..plzz paste indented code add comments tooarrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY