001package headfirst.proxy.gumballmonitor; 002 003public class GumballMachineTestDrive { 004 005 public static void main(String[] args) { 006 int count = 0; 007 008 if (args.length < 2) { 009 System.out.println("GumballMachine <name> <inventory>"); 010 System.exit(1); 011 } 012 013 try { 014 count = Integer.parseInt(args[1]); 015 } catch (Exception e) { 016 e.printStackTrace(); 017 System.exit(1); 018 } 019 GumballMachine gumballMachine = new GumballMachine(args[0], count); 020 021 GumballMonitor monitor = new GumballMonitor(gumballMachine); 022 023 024 System.out.println(gumballMachine); 025 026 gumballMachine.insertQuarter(); 027 gumballMachine.turnCrank(); 028 gumballMachine.insertQuarter(); 029 gumballMachine.turnCrank(); 030 031 System.out.println(gumballMachine); 032 033 gumballMachine.insertQuarter(); 034 gumballMachine.turnCrank(); 035 gumballMachine.insertQuarter(); 036 gumballMachine.turnCrank(); 037 038 System.out.println(gumballMachine); 039 040 gumballMachine.insertQuarter(); 041 gumballMachine.turnCrank(); 042 gumballMachine.insertQuarter(); 043 gumballMachine.turnCrank(); 044 045 System.out.println(gumballMachine); 046 047 gumballMachine.insertQuarter(); 048 gumballMachine.turnCrank(); 049 gumballMachine.insertQuarter(); 050 gumballMachine.turnCrank(); 051 052 System.out.println(gumballMachine); 053 054 gumballMachine.insertQuarter(); 055 gumballMachine.turnCrank(); 056 gumballMachine.insertQuarter(); 057 gumballMachine.turnCrank(); 058 059 System.out.println(gumballMachine); 060 061 monitor.report(); 062 } 063}