University stuff.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536
  1. class Oblig6 {
  2. static class Phrases {
  3. public static String differentWords(int n) {
  4. if (n == 1)
  5. return "There is one word.";
  6. else
  7. return "There are "+n+" different words.";
  8. }
  9. public static String numOccurrences(String str, int n) {
  10. if (n == 1)
  11. return "'"+str+"' occurs one time.";
  12. else
  13. return "'"+str+"' occurs "+n+" times.";
  14. }
  15. public static String mostCommon(String str, int n) {
  16. if (n == 1)
  17. return "'"+str+"' is the most common word, with one occurrence.";
  18. else
  19. return "'"+str+"' is the most common word, with "+n+" occurrences.";
  20. }
  21. }
  22. public static void main(String[] args) throws Exception {
  23. Ordliste ordliste = new Ordliste();
  24. ordliste.lesBok("scarlet.text");
  25. System.out.println(Phrases.differentWords(ordliste.antallOrd()));
  26. System.out.println(Phrases.numOccurrences("Holmes", ordliste.antallForekomster("Holmes")));
  27. System.out.println(Phrases.numOccurrences("elementary", ordliste.antallForekomster("elementary")));
  28. Ord vanligste = ordliste.vanligste();
  29. System.out.println(Phrases.mostCommon(vanligste.toString(), vanligste.hentAntall()));
  30. }
  31. }