Erinevus lehekülje "ITI0011RUS:task 05" redaktsioonide vahel

Allikas: Kursused
Mine navigeerimisribale Mine otsikasti
47. rida: 47. rida:
 
*/
 
*/
 
public static List<String> getWords(String text) {
 
public static List<String> getWords(String text) {
List<String> words = new ArrayList<String>();
 
 
 
 
// TODO Enter your code here
 
// TODO Enter your code here
 
 
return words;
+
return null;
 
}
 
}
 
 
63. rida: 62. rida:
 
*/
 
*/
 
public static Set<String> getUniqueWords(String text) {
 
public static Set<String> getUniqueWords(String text) {
Set<String> unique_words = new HashSet<String>();
 
 
 
 
// TODO Enter your code here
 
// TODO Enter your code here
 
 
return unique_words;
+
return null;
 
}
 
}
 
 
83. rida: 81. rida:
 
*/
 
*/
 
public static Map<String,Integer> getWordCount(String text) {
 
public static Map<String,Integer> getWordCount(String text) {
Map<String,Integer> wordCount = new HashMap<String,Integer>();
 
 
 
 
// TODO Enter your code here
 
// TODO Enter your code here
 
 
return wordCount;
+
return null;
 
}
 
}
 
 

Redaktsioon: 24. veebruar 2015, kell 23:26

Срок сдачи упражнения 9-е занятие (4-е марта).

Общая информация об упражнениях: ITI0011RUS_Practice.
Обратно на страницу предмета.

Описание

1. Прочитать текст из переменной text. Занести в ArrayList все слова.

2. Из полученного списка слов выбрать уникальные (ArrayList -> Set).

3. Для каждого слова посчитать сколько раз оно встречается. (ArrayList -> Map).

Шаблон

<source lang="java"> import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set;

public class CollectionTask {

/** * The function should read the contents of the file * designated by the filename and return its contents * as a string. * @param filename - A file name to read. * @return null if file is inaccessible (cannot be read or does not exist), * a string containing file contents otherwise. */ public static String readFile(String filename) { String text = "";

return text; }

/** * The function returns a list containing * all the words from the input string. * @param text - an input string. * @return null, if the string is not supplied, * an empty list, if the string contains no words, * a list of words otherwise. */ public static List<String> getWords(String text) {

// TODO Enter your code here

return null; }

/** * The function returns the set containing only * unique words from the input string. * @param text - an input string * @return null, if the string is not supplied, * an empty set, if the string contains no words, * a set of unique words otherwise. */ public static Set<String> getUniqueWords(String text) {

// TODO Enter your code here

return null; }


/** * The function counts how many times each word * can be found in the text and saves this * information in the Map object, where the key is * the word, and the value is the amount of times * the considered word can be found in the text. * @param text - an input string * @return null, if the string is not supplied, * an empty set, if the string contains no words, * a map of words otherwise. */ public static Map<String,Integer> getWordCount(String text) {

// TODO Enter your code here

return null; }

/** * The main function should print out * the result of the getWordCount() method. * @param args - input parameters. */ public static void main(String[] args) { // TODO Enter your code here }

} </source>