/** * Fondamenti di Informatica 1 - gr. 89 * Prova pratica di programmazione del 15 Settembre 2008 * classe DTester * classe di prova della classe D * * @author Adriano Luchetta * @version 5-09-2008 * */ import java.io.FileReader; import java.io.IOException; import java.util.Scanner; import java.util.NoSuchElementException; public class DTester { public static void main(String[] args) throws IOException { Scanner r = new Scanner(new FileReader(args[0])); D d = new D(); while (r.hasNextLine()) { Scanner tok = new Scanner(r.nextLine()); try { String key = tok.next(); String xStr = tok.next(); int x1 = Integer.parseInt(xStr); d.insert(key, x1); } catch (NoSuchElementException e) { } catch (NumberFormatException e) { } tok.close(); } r.close(); r = new Scanner(System.in); while (r.hasNextLine()) { Scanner tok = new Scanner(r.nextLine()); try { String key = tok.next(); String x2Str = tok.next(); int x2 = Integer.parseInt(x2Str); try { int x1 = d.find(key); d.insert(key, x1 + x2); } catch (NoSuchElementException e) { d.insert(key, x2); } } catch (NoSuchElementException e) { } catch (NumberFormatException e) { } tok.close(); } r.close(); String s[] = d.toSortedArray(); for (int i = 0; i < s.length; i++) System.out.println(s[i]); System.out.println("\n***TOTALE AZIONI = " + d.total() + "***"); } }