001package edu.pdx.cs410J.di; 002 003import jakarta.xml.bind.JAXBException; 004 005import java.io.File; 006import java.io.IOException; 007import java.util.Collections; 008import java.util.logging.Level; 009import java.util.logging.Logger; 010 011/** 012 * A main program that launches a book store using the "production" {@link edu.pdx.cs410J.di.BookInventory} and 013 * {@link edu.pdx.cs410J.di.CreditCardService} 014 */ 015public class BookStoreApp 016{ 017 public static void main(String... args) throws JAXBException, IOException 018 { 019 String tmpdir = System.getProperty( "java.io.tmpdir" ); 020 File directory = new File( tmpdir ); 021 BookInventory inventory = new BookDatabase( directory ); 022 addBooks(inventory); 023 CreditCardService cardService = new FirstBankOfPSU( "localhost", 8080 ); 024 025 Logger logger = Logger.getLogger( "edu.pdx.cs410J.Logger" ); 026 logger.setLevel( Level.INFO ); 027 028 CheckoutPanel panel = new CheckoutPanel( inventory, cardService, logger ); 029 BookStoreGUI gui = new BookStoreGUI( panel ); 030 gui.pack(); 031 gui.setVisible( true ); 032 } 033 034 protected static void addBooks( BookInventory inventory ) 035 { 036 addBook( inventory, new Book( "The Pragmatic Programmer", "Andrew Hunt", 29.95 ), 4 ); 037 addBook( inventory, new Book("Winning", "Jack Welch", 15.95), 3 ); 038 addBook( inventory, new Book( "Agile Estimating and Planning", "Mike Cohn", 35.99), 2); 039 } 040 041 private static void addBook( BookInventory inventory, Book book, int copies ) 042 { 043 inventory.add( Collections.nCopies( copies, book ).toArray(new Book[copies]) ); 044 } 045}