@Override public void actionPerformed(ActionEvent e) { EntryReader er = new EntryReader(); String entriesFilename = entriesTxt.getText(); if (entriesFilename.isEmpty()) { errorLabel.setText("Entries filename must not be empty."); return; } Map<Branch, List<Entry>> entries; try { entries = er.read_entries(entriesFilename); Set<Branch> keys = entries.keySet(); String prizesFilename = prizesTxt.getText(); if (prizesFilename.isEmpty()) { errorLabel.setText("Prizes filename must not be empty."); return; } Map<String, List<Prize>> store_prizes = er.getPrizes(prizesFilename); File results = new File("results.csv"); PrintWriter writer = null; try { writer = new PrintWriter(results); WinnerPicker winnerPicker = new WinnerPicker(); for (Branch branch : keys) { // writer.println(branch.getBranch_name() + " : " + entries.get(branch).size()); List<Entry> branch_entries = entries.get(branch); for (Prize prize : store_prizes.get("Store")) { Winner winner = winnerPicker.pickWinner(prize, branch_entries); winner.getEntry().getPrizes().add(prize); Prize current_branch_prize = new Prize(prize); current_branch_prize.setWinner(winner); branch.getPrizes().add(current_branch_prize); writer.print(branch.getAccount()); writer.print(","); writer.print(branch.getBranch_name()); writer.print(","); writer.print(prize.getPrize_description()); writer.print(","); writer.print(winner.getEntry().getCustomer_name()); writer.print(","); writer.print(winner.getEntry().getTelephone()); writer.print(","); writer.println(winner.getEntry().getAddress()); } } } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } finally { writer.close(); } } catch (Exception e3) { errorLabel.setText(e3.getMessage()); } }