import java.io.*; import java.util.*; import java.text.DecimalFormat; public class TicketCounter { public static void main( String[] args ){ try { String line; File fileName = new File("tickets.txt"); boolean onPerson = false; boolean ticketTime = false; boolean paid = false; double amount = 0; ArrayList personList = new ArrayList(); DecimalFormat money = new DecimalFormat("0.00"); BufferedReader fileIn = new BufferedReader(new FileReader(fileName)); Person currPer = new Person(); while (( line = fileIn.readLine()) != null){ line = line.trim(); if( !line.trim().equals("")) { if( line.equals("") ) onPerson = true; else if( line.equals("") ) { onPerson = false; personList.add(currPer); currPer = new Person(); }else if(onPerson) { if(line.contains("")) { String last = line.replaceAll("", ""); last = last.replaceAll("", "").trim(); currPer.setLast(last); } if(line.contains("")) { String first = line.replaceAll("", ""); first = first.replaceAll("", "").trim(); currPer.setFirst(first); } if(line.contains("")) { String number = line.replaceAll("", ""); number = number.replaceAll("", "").trim(); currPer.setNumber(number); } if(line.equals("")) ticketTime = true; if(line.equals("")) { ticketTime = false; currPer.addTicket(amount, paid); } if(ticketTime) { if(line.contains("")) { String paidSymbol = line.replaceAll("", ""); paidSymbol = paidSymbol.replaceAll("", "").trim(); paid = paidSymbol.equals("Y"); } if(line.contains("")) { String amt = line.replaceAll("", ""); amt = amt.replaceAll("", "").trim(); amount = Double.parseDouble(amt); } } } } } double totalPaid = 0; double total = 0; for( int i = 0; i < personList.size(); i++ ) { System.out.println( personList.get(i).toString()); totalPaid = totalPaid + personList.get(i).getPaid(); total = total + personList.get(i).getTotal(); } System.out.println("Total paid: " + money.format(totalPaid) + ", Total unpaid: " + money.format((total-totalPaid))); } catch(Exception e) { System.err.println("Something went wrong."); } } }