123456789101112131415161718192021222324252627282930313233343536 |
- class Oblig6 {
- static class Phrases {
- public static String differentWords(int n) {
- if (n == 1)
- return "There is one word.";
- else
- return "There are "+n+" different words.";
- }
-
- public static String numOccurrences(String str, int n) {
- if (n == 1)
- return "'"+str+"' occurs one time.";
- else
- return "'"+str+"' occurs "+n+" times.";
- }
-
- public static String mostCommon(String str, int n) {
- if (n == 1)
- return "'"+str+"' is the most common word, with one occurrence.";
- else
- return "'"+str+"' is the most common word, with "+n+" occurrences.";
- }
- }
-
- public static void main(String[] args) throws Exception {
- Ordliste ordliste = new Ordliste();
- ordliste.lesBok("scarlet.text");
-
- System.out.println(Phrases.differentWords(ordliste.antallOrd()));
- System.out.println(Phrases.numOccurrences("Holmes", ordliste.antallForekomster("Holmes")));
- System.out.println(Phrases.numOccurrences("elementary", ordliste.antallForekomster("elementary")));
-
- Ord vanligste = ordliste.vanligste();
- System.out.println(Phrases.mostCommon(vanligste.toString(), vanligste.hentAntall()));
- }
- }
|