/*
 * Brian Billow
 * 10/23/03
 * Period 7
 * Purpose: create a guestbook for my AP Comp Sci website using java
 */

public class guestbook
{
	public static void main(String[] args)
	{
				
		System.out.println("Hello, and welcome to the guestbook of Brian Billow");
		
		String lName;                       // declares variable lName as a string
		String fName;                       // declares variable fName as a string
		String Email;                       // declares variable Email as a string
		String fileName = "Guestbook.txt";  // declares the file name
	    String Line = "";                   // declares String Line
	   	int EN = 0;                         // declares Entry number as EN
	    int GL;                             // declares variable GL as a integer
			
		EasyReader console = new EasyReader();     // Calls the EasyReader class
		EasyWriter outFile = new EasyWriter("Guestbook.txt", "app");    // Calls the EasyWriter class
		
		System.out.println("Please input your last name:");
		lName = console.readLine();                // Prompts user to input their last name
		
		if ( lName.equalsIgnoreCase( "admin" ))    // Checks to see if Variable lName is equal to Admin or admin or ADMIN 
		{
		 	
		 	System.out.println("Welcome Admin!");
			System.out.println("Here is all of the info that has been saved so far");
			System.out.println("");
			
			EasyReader inFile = new EasyReader(fileName);    // tells the program to open the file "guestbook"
	   	    
	   	    while (!inFile.eof())                  // Checks to see if it is at the end of the file
	   	    {
	   	    	EN = EN + 1;                       // adds 1 to Entry Number
	       		Line = inFile.readLine();          // reads line 1 from that file
				
				if (Line != null)                  // Checks to see if Line is null
				{
					System.out.println("Entry " + EN);  // displays entry number
  					System.out.println( Line );         // displays all info saved in the file
  					System.out.println("");
  				}
  				else
  				{
  					System.out.println("this is all of the info that has been saved so far");
  					System.out.println("");
  				}
  			}
  		}	
		else
		{
			System.out.println("Please input your First Name");
			fName = console.readLine();    // Prompts user to input their first name
			System.out.println("Please input your Email Address");
			Email = console.readLine();    // Prompts user to input their email address
			System.out.println("Please input your Grade Level");
			GL = console.readInt();        // Prompts user to input their grade level
				
			outFile.println("Last Name: " + lName + ", First Name: " + fName + ", Email Address: " + Email + ", Grade Level: " + GL);   // Stores the variable into Guestbook.txt
			outFile.close();               // Closes the guestbook file   
			System.out.println("Thanks you for your time");
		}
	}
}
	


	

