/* * TODO: Put file header here. */ package schilling; import java.util.Scanner; /** * A simple test program for SE1021 laboratory assignment 2 in * winter 2014-2015. * @author schilling with minor edits by taylor and yoder * @version 1.1-20141205 */ public class SimpleMain { /** * Provides a menu to obtain book and article references and then * display them to the console window. * @param args ignored */ public static void main(String[] args) { // This variable will hold the references used. ReferenceHolder references = new ReferenceHolder(); // Setup the keyboard as an input. Scanner in = new Scanner(System.in); char entry = '-'; do { // Prompt the user for input. printPrompt(); // Get the entry. String input = in.nextLine(); if(input.length()==1) { entry = input.charAt(0); } switch (entry) { case '1': // Add a new book. Reference reference = createGenericEntry(in); references.addReference(reference); break; case '2': // Print everything. references.printAllBibtexEntries(); break; } } while (entry!='0'); } /** * Displays main menu to the console. */ public static void printPrompt() { System.out.println("Enter 0 to exit the program."); System.out.println("Enter 1 to enter a new generic reference."); System.out.println("Enter 2 to printout the entries in Bibtex format."); } /** * This method will allow the user to enter the information for the book. * @param in This is the keyboard. * @return A book will be returned. */ public static Reference createGenericEntry(Scanner in) { System.out.println("Enter the author"); String author = in.nextLine(); System.out.println("Enter the title"); String title = in.nextLine(); System.out.println("Enter the copyright year for the book."); int copyright = Integer.parseInt(in.nextLine()); return new Reference(author, title, copyright); } }