import easyio.*; import java.util.*; class Eliza { public static void main (String [] args) { if (args.length !=1) { System.out.println(" bruk: >java Eliza "); } else { Samtale sam = new Samtale(); sam.lesFraFil(args[0]); sam.snakk(); } } // end main } class Samtale { HashMap hash = new HashMap(); In tast = new In(); void lesFraFil(String filnavn) { In fil = new In(filnavn); while (!fil.lastItem()) { String s?keord = fil.inWord(); String svar = fil.inLine(); hash.put(s?keord, svar); } fil.close(); System.out.println("Antall ord lest: " + hash.size()); } void snakk() { while (true) { String ord; // Random r = new Random(); System.out.print("> "); boolean funnetMatch = false; do { ord = tast.inWord().toLowerCase(); // random selection of next element // if (r.nextInt(4) < 3 && tast.hasNextChar()) ord = tast.inWord().toLowerCase(); if (hash.containsKey(ord)) { String svar = hash.get(ord); System.out.println(svar); funnetMatch = true; } } while (tast.hasNextChar() && !funnetMatch); if (!funnetMatch) { System.out.println("Interessant. Fortell mer."); } if (tast.hasNextChar()) { tast.readLine(); // T?mmer inputbufferet } } } // end snakk }