Erinevus lehekülje "ITI0011-2015:harjutus 05" redaktsioonide vahel
P (Ago teisaldas lehekülje ITI0011:harjutus 05 pealkirja ITI0011-2015:harjutus 05 alla) |
|||
| (ei näidata sama kasutaja 3 vahepealset redaktsiooni) | |||
| 3. rida: | 3. rida: | ||
Üldine informatsioon harjutuste kohta: [[ITI0011:harjutused]]. | Üldine informatsioon harjutuste kohta: [[ITI0011:harjutused]]. | ||
| − | Näidissisend: [[Meedia:Garbage_Collector_Article.txt|Garbage_Collector_Article.txt]] (kood peab töötama suvaliste etteantud sõnega). | + | Näidissisend: [[Meedia:Garbage_Collector_Article.txt|Garbage_Collector_Article.txt]] (kood peab töötama suvaliste etteantud sõnega). |
| − | Näpunäiteid (täieneb): [[Java:Kogumid|Kogumid]] | + | == Reeglid == |
| + | |||
| + | * Sõnad tuleb "tõlkida" selliseks, et kõik tähed on väikesed tähed. Ehk siis "Tere" peaks erinevatesse kogumitesse minema "tere"-na. | ||
| + | * Sõna moodustab järjestikuna tähtede ja numbrite alamsõne. Lisaks lähevad sõnana arvesse numbrite ja tähtede vahel olev ' (ülakoma või ühekordne jutumärk) märk. Ehk siis üks sõna on "I'll" ja "don't" jne. | ||
| + | * Kõik muud sümbolid (välja arvatud need, mis eelmises punktis kirjeldatud) on sõnade eraldajad | ||
| + | * Tühi sõna ("") ei lähe sõnana arvesse. | ||
| + | |||
| + | == Näited == | ||
| + | |||
| + | <code>[]</code> tähistavad elemente kas listis või setis. <code>{'a': 12}</code> tähistab HashMapis olevat informatsiooni (sõna 'a' esineb 12 korda). Teie ei pea midagi sellist välja printima. Need on siin lihtsalt toodud näited, mida funktsioon peab <code>return</code>'ima. | ||
| + | |||
| + | <pre> | ||
| + | getWords(null) => null | ||
| + | getWords("") => [] | ||
| + | getWords(" ") => [] | ||
| + | getWords("tere") => ["tere"] | ||
| + | getWords("tere tulemast") => ["tere", "tulemast"] | ||
| + | getWords("Tere tere") => ["tere", "tere"] | ||
| + | getWords("tere-tere ") => ["tere", "tere"] | ||
| + | |||
| + | getUniqueWords(null) => null | ||
| + | getUniqueWords("") => [] | ||
| + | getUniqueWords("tere Tere") => ["tere"] | ||
| + | |||
| + | getWordCount(null) => null | ||
| + | getWordCount("") => {} | ||
| + | getWordCount("tere") => {"tere": 1} | ||
| + | getWordCount("tere tere Tere") => {"tere": 3} | ||
| + | </pre> | ||
| + | |||
| + | == Näpunäited == | ||
| + | |||
| + | Näpunäiteid (täieneb): [[Java:Kogumid|Kogumid]], [[Java:Failist_lugemine]] | ||
== Lähtekood == | == Lähtekood == | ||
Viimane redaktsioon: 22. veebruar 2016, kell 07:51
Harjutuse tähtaeg on 9. praktikum (3. märts).
Üldine informatsioon harjutuste kohta: ITI0011:harjutused.
Näidissisend: Garbage_Collector_Article.txt (kood peab töötama suvaliste etteantud sõnega).
Reeglid
- Sõnad tuleb "tõlkida" selliseks, et kõik tähed on väikesed tähed. Ehk siis "Tere" peaks erinevatesse kogumitesse minema "tere"-na.
- Sõna moodustab järjestikuna tähtede ja numbrite alamsõne. Lisaks lähevad sõnana arvesse numbrite ja tähtede vahel olev ' (ülakoma või ühekordne jutumärk) märk. Ehk siis üks sõna on "I'll" ja "don't" jne.
- Kõik muud sümbolid (välja arvatud need, mis eelmises punktis kirjeldatud) on sõnade eraldajad
- Tühi sõna ("") ei lähe sõnana arvesse.
Näited
[] tähistavad elemente kas listis või setis. {'a': 12} tähistab HashMapis olevat informatsiooni (sõna 'a' esineb 12 korda). Teie ei pea midagi sellist välja printima. Need on siin lihtsalt toodud näited, mida funktsioon peab return'ima.
getWords(null) => null
getWords("") => []
getWords(" ") => []
getWords("tere") => ["tere"]
getWords("tere tulemast") => ["tere", "tulemast"]
getWords("Tere tere") => ["tere", "tere"]
getWords("tere-tere ") => ["tere", "tere"]
getUniqueWords(null) => null
getUniqueWords("") => []
getUniqueWords("tere Tere") => ["tere"]
getWordCount(null) => null
getWordCount("") => {}
getWordCount("tere") => {"tere": 1}
getWordCount("tere tere Tere") => {"tere": 3}
Näpunäited
Näpunäiteid (täieneb): Kogumid, Java:Failist_lugemine
Lähtekood
<source lang="java"> import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet;
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 ArrayList<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 HashSet<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 HashMap<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>