import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.awt.Desktop;
import java.net.URI;
import java.util.Scanner;

public class TestMember {

public static void main( String args[] ) {
	Scanner help = new Scanner(System.in);
	writeMembersToFile ( "mem.txt" );
	showMembersInFile( "mem.txt");
	System.out.printf("Enter H/h/? for help, or command : \n");
	char help = scanner.next();
}

public static void showMenu() {
	System.out.println("======================== CS 3990 Assignment 1 ===============");
	System.out.println("G/g:   Ask for a N, and generate N members of mixed " +
                    	"		Member class's objects, and store in a Vector " +
		       			"and a array Objects.");
	System.out.println("S/s/ : Sort the members in the vector and array in" +
                    	"       ascending order. ");
	System.out.println("O/o/ : Save objects inside vector into a HTML file" +
						"       with objects saved in the format of HTML" +
						"		Table.");
	System.out.println("F/f  : Show HTML file contents on screen.");
	System.out.println("L/l  : Launch the default internet browser to" +
						"       display the generated HTML file.");
	System.out.println("--------------------------------------------------");
	System.out.println("H/h/?: Display this menu.");
	System.out.println("E/e  : Exit");
	System.out.println("======================== CS 3990 Assignment 1 ===============");
}

public static void showHTMLFile( String fileName ) {
	if(Desktop.isDesktopSupported()) {
	   try {
			File file = new File( hw01.html ); // fileNae example: "hw01.html".
			Desktop.getDesktop().browse( file.toURI() );
	   } catch ( Exception e ) { e.printStackTrace(); }
   }
}

static void showMembersInFile( String fileName ) {
	FileReader fin = null;
	int ch ;
	try {
		fin = new FileReader( fileName  );
		while ( ( ch = fin.read() ) != -1 )
		System.out.printf("%c", ch);
		fin.close();
	} catch (IOException e ) { e.printStackTrace(); }
}

static void writeMembersToFile ( String fileName ) {
	FileWriter fout = null;
	Member m = new Member ();
	char[] cArr = null;

	try {
		fout = new FileWriter( fileName );
		for ( int i = 0; i < 20; i ++ ) {
			System.out.printf("Member generated: %s\n", m );
			cArr = m.toString().toCharArray();
			for (int j = 0; j < cArr.length; j++ ) fout.write( cArr[j] ); 
			fout.write('\n');
			m.generate(); 
		}
		fout.close();
	} catch (IOException e) { e.printStackTrace(); }
}
	
}
