//The function searchByCost searches
        //for each book that falls within the given
        //price range.
        public void searchByCost(double min, double max)
	{	
		BookRecord temp = new BookRecord();

		temp = m_pHead;
		int tracker = 0; //Tracks every book found
		
		if (m_pHead == null) //Checks if there is anything in the list, prints message if list is empty
		{
			Console.Error.WriteLine("There are no contents in this list!");
		}
			
		
		while ((temp != null)) //The list is searched till end
		{
			//Checks to see if the cost of the book falls within the range (min & max)
			if ((temp.getCost() >= min) && (temp.getCost() <= max))
			{
				temp.printRecord(); //If it does, the information is printed.
				tracker++;
			}
			temp = temp.getNext();
		}
		
		if (tracker <= 0) //If no book is found in that price range
		{
			Console.WriteLine("No item(s) found for this price range!");
		}
	}
 //The function printAll goes through
 //the list and prints off each book Record.
 public void printAll()
 {
     if (m_pHead == null) //Checks if there is anything in the list, prints message if list is empty
     {
         Console.Error.WriteLine("Nothing to print.There are no contents in this list!");
         return;
     }
     BookRecord temp = new BookRecord();
     temp = m_pHead;
     while (temp != null)//The while loop runs through the list until it ends
     {
         temp.printRecord();
         temp = temp.getNext();
     }
 }
        //The function searchByClassification searches
        //for a book by the given classification number
        //and prints the information.
        public void searchByClassification(int cl)
	{
		if (m_pHead == null) //Checks if there is anything in the list, prints message if list is empty
		{
			Console.Error.WriteLine("There are no contents in this list!");
			return;
		}
		
		BookRecord temp = new BookRecord();
		int tempCL; 
		int tracker = 0; //Tracks every book found
		
		temp = m_pHead;
		tempCL = temp.getClassification();
		
		//This for loop searches the list until it ends
		while (temp != null)
		{
			tempCL = temp.getClassification();
			if(tempCL == cl)//if the classification numbers match,
			{
				temp.printRecord(); //the information is printed
				tracker++;
			}
			temp = temp.getNext(); // iterate
		}
		if (tracker <= 0)
		{
			Console.WriteLine("No item(s) with that classification number!");
		}
	}
        public static void Main(String[] args)
        {

            //Testing for instance creation
            Console.WriteLine("\nTesting the default constructor for BookRecord...");
            BookRecord book1 = new BookRecord();
            book1.printRecord();
            //setter tests
            Console.WriteLine("\nTesting the setter functions of BookRecord...");
            String lebook = "James Potter";
            book1.setName(lebook);
            book1.setClassification(150);
            book1.setCost(95);
            book1.setStockNum(13232);
            book1.setNumberInStock(5);
            book1.printRecord();
            String lebook2 = "Harry Potter";
            BookRecord book2 = new BookRecord(lebook2, 111, 2, 4.33);
            //getter tests
            Console.WriteLine("\nTesting the getter functions of BookRecord...");
            book2.printRecord();
            Console.WriteLine(book1.getName());
            Console.WriteLine(book1.getClassification());
            Console.WriteLine(book1.getCost());
            Console.WriteLine(book1.getNumberInStock());
            Console.WriteLine(book1.getStockNum());
            //static test
            Console.WriteLine("\nTesting static instances of BookRecord...");
            BookRecord book3 = new BookRecord();
            book3.printRecord();
            String lebook3 = "James Potter";
            book3.setName(lebook3);
            book3.setClassification(150);
            book3.setCost(95);
            book3.setStockNum(13232);
            book3.setNumberInStock(5);
            book3.printRecord();
            //Book Inventory testing!
            Console.WriteLine("\nBook Database testing begins here...");
            //Initializing some of the stubs/drivers
            Book_Database Store = new Book_Database();
            BookRecord Book1 = new BookRecord("The Great Gatsby!", 21245, 343, 19.45);
            BookRecord Book2 = new BookRecord("The Stranger", 456121, 2342, 20.55);
            BookRecord Book3 = new BookRecord("Harry Potter", 234215, 443, 49.99);
            BookRecord book = new BookRecord();
            //Testing read Inventory & printAll & getNextLine
            Console.WriteLine("\nTesting read database...");
            Store.read_Database("BookData.txt");
            Console.WriteLine("\nTesting printAll()");
            Store.PrintAll();
            //Testing addBook
            Console.WriteLine("\nTesting addBook, (& from BookRecord->setNext, getNext)...");
            Store.addBook(Book1);
            Store.addBook(Book3);
            Store.addBook(Book2);
            Store.PrintAll();
            //Testing removeBook
            Console.WriteLine("\nTesting the removeBook function....");
            Store.removeBook(456121);
            Store.removeBook(4561);
            Store.PrintAll();
            //Testing BookRecord *searchByStockNumber
            Console.WriteLine("\nTesting the BookRecord *searchByStockNumber function");
            Console.WriteLine("First one");
            book = Store.searchByStockNumber(234215);
            if (book == null)
            {
                Console.WriteLine("Nothing here bob");
            }
            else
            {
                book.printRecord();
            }
            Console.WriteLine("second one");
            book = Store.searchByStockNumber(156121);
            if (book == null)
            {
                Console.WriteLine("Sorry, nothing here bob");
            }
            else
            {
                book.printRecord();
            }
            //Testing searchByClassification
            Console.WriteLine("\nTesting the searchByClassification function");
            Store.searchByClassification(443);
            Store.searchByClassification(000);
            //Testing searchByCost
            Console.WriteLine("\nTesting the searchByCost function");
            Console.WriteLine("For 10.00 to 58.85");
            Store.searchByCost(10.00, 58.65);
            Console.WriteLine("For 20. 55 to 100");
            Store.searchByCost(20.55, 100);
            Console.WriteLine("For 100 to 1000");
            Store.searchByCost(100, 1000);
            //Testing ClearList
            Console.WriteLine("\nTesting the ClearList function");
            Store.ClearList();
            Console.WriteLine("list cleared \n");
            Store.PrintAll();
            //Re-Testing all search functions after list is cleared
            Console.WriteLine("Re-Testing all search functions after list is cleared");
            Console.WriteLine("Re-Testing searchByStockNumber");
            book = Store.searchByStockNumber(4567);
            book = Store.searchByStockNumber(156121);

            //Re-testing searchByClassification
            Console.WriteLine("\nRe-Testing searchByClassification");
            Store.searchByClassification(443);
            Store.searchByClassification(000);

            Console.WriteLine("\nRe-Testing searchByCost");
            Console.WriteLine("For 10.00 to 58.85");
            Store.searchByCost(10.00, 58.65);

            Console.WriteLine("For 20. 55 to 100");
            Store.searchByCost(20.55, 100);
            Console.WriteLine("For 100 to 1000");
            Store.searchByCost(100, 1000);

        }
 //The function PrintAll() recursively prints
 //all book records stored in the binary tree
 //Only the system directly interacts with this function
 private void PrintAll(BookRecord rt)
 {
     if (rt != null)
     {
         PrintAll(rt.getLeft());
         rt.printRecord();
         PrintAll(rt.getRight());
     }
 }
 //The function searchByCost recursively searches
 //for each book that falls within the given
 //price range.
 //If found, it prints out the book information
 //Only the system directly interacts with this function
 private void searchByCost(double min, double max, BookRecord rt)
 {
     if (rt != null)
     {
         //Checks to see if the cost of the book falls within $10 of the range (min & max).
         if ((rt.getCost() >= (min - 5)) && (rt.getCost() <= (max + 5)))
         {
             rt.printRecord();//If it does, the information is printed
         }
         searchByCost(min, max, rt.getLeft());
         searchByCost(min, max, rt.getRight());
     }
 }
 private void searchByClassification(int cl, BookRecord rt)
 {
     int tempCL;//Since BookRecord::getClassification() is a
     //pass by reference function, tempCL is used to
     //obtain the classification number of the book.
     if (rt != null)
     {
         tempCL = rt.getClassification();
         if (cl == tempCL)
         {
             rt.printRecord();
         }
         searchByClassification(cl, rt.getLeft());
         searchByClassification(cl, rt.getRight());
     }
 }