/** * Console program for managing IceCreamStation objects. * * @author JP Vergara * @version 24 February 2008 */ import java.util.Scanner; public class IceCreamStationConsole { public static void main( String args[] ) { Scanner in = new Scanner( System.in ); IceCreamStation ben = new IceCreamStation( 50.00 ); IceCreamStation jerry = new IceCreamStation( 50.00 ); System.out.println( "This program manages ice cream stations" ); System.out.println( "------------------------------------------" ); System.out.println( "Choose an action (type the number)" ); System.out.print( "(1) Buy cones (2) Buy ice cream (3) Sell ice cream (4) Exit > "); int option = in.nextInt(); while ( option != 4 ) // keep on going until 4 (Exit) is typed { System.out.print( "Name of vendor (type ben or jerry) ? " ); String name = in.next(); IceCreamStation vendor; if ( name.equals( "ben" ) ) vendor = ben; else // if what is typed is not ben, let's assume jerry vendor = jerry; if ( option == 1 ) { System.out.print( "How many boxes? " ); int numBoxes = in.nextInt(); vendor.buyCones( numBoxes ); } else if (option == 2 ) { System.out.print( "How many pints? " ); double numPints = in.nextDouble(); vendor.buyIceCream( numPints ); } else if (option == 3) { System.out.print( "Type number of cones and unit price: " ); int coneCount = in.nextInt(); double price = in.nextDouble(); vendor.sellIceCreamCones( coneCount, price ); } else System.out.println( "No action performed." ); System.out.printf( "Cash: $%.2f, Inventory: %.2f pints, %d cones\n", vendor.getCashOnHand(), vendor.getIceCreamLeft(), vendor.getConesLeft() ); System.out.println( "------------------------------------------" ); System.out.println( "Choose an action (type the number)" ); System.out.print( "(1) Buy cones (2) Buy ice cream (3) Sell ice cream (4) Exit > "); option = in.nextInt(); } System.out.println( "Thank you, come again." ); } }