public CashierInterface(Database database) { this.db = database; movies = db.getMovies(); times = db.getShowTimes(movies[0]); movieList = new DropdownView(movies); timesList = new DropdownView(times); movieList.addActionListener(updateTimes); feedback.setEditable(false); feedback.setLineWrap(true); feedback.setWrapStyleWord(true); Display movies = new Display(movieList, "Select Movie:", null); Display times = new Display(timesList, "Select Showing:", null); Display tix = new Display( tickets, "How many of each ticket " + "type would you like?(" + getTicketAnnotation() + ")", null); Display feedbk = new Display(feedback, "Info", null); add(movies); add(times); add(tix); add(new Display(new TextAreaView())); add(feedbk); add(ap); }
public void sellTickets() { StringTokenizer st = new StringTokenizer(tickets.getViewState(), ","); ArrayList<Map.Entry<String, Integer>> disCodes = db.getDiscountsAndPrices(); int discountCodeCount = disCodes.size(); if (st.countTokens() == discountCodeCount) { ArrayList<Map.Entry<String, Integer>> order = new ArrayList<Map.Entry<String, Integer>>(); int orderSize = 0; int price = 0; for (Map.Entry<String, Integer> codeAndPrice : disCodes) { int ticCount = Integer.parseInt(st.nextToken()); orderSize = orderSize + ticCount; order.add(new AbstractMap.SimpleEntry<String, Integer>(codeAndPrice.getKey(), ticCount)); price = price + (codeAndPrice.getValue() * ticCount); } try { Movie m = db.getMovie(movieList.getViewState(), timesList.getViewState()); int attendance = m.getAttendance(); int capacity = m.getTheater().getCapacity(); if (capacity >= attendance + orderSize) { feedback.setViewState( "Please tender $" + price + " to the cashier and proceed to theater " + m.getTheater().getID()); for (Map.Entry<String, Integer> suborder : order) { m.addOrder(suborder.getKey(), suborder.getValue()); } } else { feedback.setViewState( "I'm sorry, but the showing of " + m.toString() + " is sold out. Please select another film."); } } catch (Exception e) { System.out.println(e); } } else { String err = "Malformed ticket order: Input must be comma " + "separated, without spaces," + " with the value in each postion reflecting " + "the number of each type of ticket you would like." + "e.g. If the discount codes are Adult,Child,Senior " + "2,1,0 would represent an order of two adults and" + " one child"; System.out.println(err); feedback.setViewState(err); } }