Hi need help writing a method in java:
It should accept a file name as a parameter, and then open the file and return how many unique words there are in the file (ignore capitalization). If possible can you show how to use a TreeSet as a storage to put in the unique words and then return its size.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.TreeSet;
public class NumberOfUniqueWords {
public static int countUniqueWords(String filename) {
TreeSet<String> set = new TreeSet<>();
File file = new File(filename);
try {
Scanner fin = new Scanner(file);
while (fin.hasNext()) {
set.add(fin.next().toLowerCase());
}
fin.close();
} catch (FileNotFoundException e) {
System.out.println(file.getAbsolutePath() + " is not found!");
}
return set.size();
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter file name: ");
System.out.println("Number of words in file is " + countUniqueWords(in.nextLine()));
}
}
Hi need help writing a method in java: It should accept a file name as a...
I need help writing the following java Java Method below. I just need a method to take a user inputted First or Last Name and return the associated phone number, thank you! import java.util.*; import java.io.*; class PhoneList { public static void main(String[] args) throws Exception { boolean loop = true; File file = new File("PhoneList_Data.txt"); FileWriter fw = new FileWriter(file, true); fw.write("PhoneList Data"); fw.write("\n" + "Last, First: 6041337567, 2181731566"); // do { } (loop) fw.close(); } //...
Capitalization JAVA In this program, you will read a file line-by-line. For each line of data (a string), you will process the words (or tokens) of that line one at a time. Your program will capitalize each word and print them to the screen separated by a single space. You will then print a single linefeed (i.e., newline character) after processing each line – thus your program will maintain the same line breaks as the input file. Your program should...
I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt Project#3 is an extension of the concepts and tasks of Lab#3. You will again read the dictionary file and resize the array as needed to store the words. Project#3 will require you to update a frequency counter of word lengths every time a word is read from the dictionary into the wordList. When your program is finished this histogram array will contain the following:...
Please I need help. Java language Method name: getScores Return value is a String of numbers scaled so that the highest number in the parameter String becomes 100 and all the other numbers are moved up by the same amount. This String should also be numbers separated by spaces with no additional characters. The order of the numbers should stay the same, so that a number in the original string has the equivalent scaled number in the returned string in...
Please I need help. Java language Method name: getScores Return value is a String of numbers scaled so that the highest number in the parameter String becomes 100 and all the other numbers are moved up by the same amount. This String should also be numbers separated by spaces with no additional characters. The order of the numbers should stay the same, so that a number in the original string has the equivalent scaled number in the returned string in...
This is a java assignment Please help me Write the body of the fileAverage() method. Have it open the file specified by the parameter, read in all of the floating point numbers in the file and return their average (rounded to 1 decimal place). For the testing system to work, don't change the class name nor the method name. Additionally, the file will have different contents during testing. public class Main { public double fileAverage( String filename ){ }...
JAVA Only need help with (D) if you can explain to me where this method needs to go? Should I place this method name ( SETNAME()) in the main method or in the gpa method ?? D) - Add one more method name it setName(), this method should read the name of student from input stream and return to main method. Write a method to accept n integer number between 0 and 100 and return the average. B)-Write a method...
Need some help on this Python Problem called "unique words" the text.txt file can be any .txt file with words in it. Write a program that opens a specified text file and then displays the number of unique words in the text file after stripping all the white spaces, comma, and the punctuation marks and list of all the unique words found in the file. The list should be sorted in alphabetical order. The program should handle the ‘file not...
Hi everyone! I need help on my Java assignment. I need to create a method that is called sumIt that will sum two values and will return the value.It should also invoke cubeIt from the sum of the two values. I need to change the currecnt program that I have to make it input two values from the console. The method has to be called sumIt and will return to the sum that will produce the cube of the sum...
To insure that file output is written to the disk you need to execute what method? a. commit() b. write() c. close() d. complete() The following is called the ________ of a function. def myFunction(x,y) : a. header b. footer c. sentinel d. index True or False: A commonly used program that uses regular expressions is grep. True or False: In Python exception handling provides a mechanism for passing control from the point of the error detection to a handler...