
// Main class (main program)
// ========== 

import java.io.*;
import java.util.*;
import java.lancs.BasicIo;

class Main

{

	static DirBase dirBase;


	static void findInteractive() throws IOException
	{
		String sname;
		System.out.print("type surname : ");
		System.out.flush();
		sname = BasicIo.readString();
		DirEntry rec = dirBase.find(sname);
		System.out.println(rec);
	}

	static void addInteractive() throws IOException
	{
		String sname, fname;
		int number;
		System.out.print("Surname : ");
		System.out.flush();
		sname = BasicIo.readString();
		System.out.print("Forename : ");
		System.out.flush();
		fname = BasicIo.readString();
		System.out.print("Number : ");
		System.out.flush();
		number = BasicIo.readInteger();
		dirBase.add(sname,fname,number);
	}

	static void interpCommands() throws IOException
	{
		String com;
		boolean goon = true;

		while (goon)
		{
			System.out.print(">> ");
			System.out.flush();
			com = BasicIo.readString();

			switch (com.charAt(0))
			{
			case 's' :
				goon = false;
				break;
			case 'f' :
				findInteractive();
				break;
			case 'a' :
				addInteractive();
				break;
			case 'i' :
				dirBase.indexPrint();
				break;
			case 'p' :
				dirBase.mainPrint();
				break;
			case 'h' :
				listCommands();
				break;
			default :
				System.out.println("Unknown command");
				break;
			};
		} /* end of command loop */

	} /* end of interpCommands */

	private static void listCommands()
	{
		System.out.println("s : stop\nf : find\na : add");
		System.out.println("i : index print\np : records print");
		System.out.println("h : help");
	}

	public static void main(String[] args) throws IOException
	{
		dirBase = new DirBase("telinfo");
		interpCommands();
		dirBase.close();

	}

}

