/** * This database program stores and makes queries about animal names. * @author */ import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.Arrays; import java.util.ArrayList; import java.awt.event.*; public class DataBaseApp { private TheDataBase db = new TheDataBase(); public Scanner scanner = new Scanner (System.in); public DataBaseApp() { query(); } public String[] choices = { "Print all animals.", "Add an animal.", "quit"}; public void query() { int c = 0; while ( c!= 3 ) { // not quitting c = getChoice(); if (c==0) { // print all animals System.out.print(printAnimals()); } if (c==1) { // add animal addAnimal(); } if (c==2) { // quit System.out.println("\n\nGood-bye"); System.exit(0); } } } public int getChoice() { int c; System.out.print("\n\nThis is the Animal Database. \nBelow are the possible actions.\n"); for (int i = 0; i < choices.length;i++) { System.out.println(" " + i + ": " + choices[i]); } System.out.print("Please enter your choice: "); c = Integer.parseInt( scanner.nextLine() ); System.out.print("\n\nYou entered: " + choices[c]); return c; } /** Print out all of the data */ public String printAnimals() { return "\nThe animals are : " + db.toString(); } /** Add a new animal */ public void addAnimal() { System.out.print("\nPlease enter the animal name you wish to add: "); String name = scanner.nextLine().trim().toLowerCase(); System.out.print("\nAdding " +name); db.addAnimal(name); } // This is where the program starts public static void main(String[] args) { DataBaseApp app = new DataBaseApp(); } }