/*
 * @topic T11330 Spring 2016 Serializable demo
 * @brief App demonstrating Serializable interface
*/
package demo;

public class MainApp {

    public static void main(String[] args) {
        
        for ( int id = 100; true ; ++id ) {
            
            Employee employee = new Employee();
            employee.name = Validator.getString(
                    Validator.sc, "Employee name: ");
            String fileName = employee.name;
            
            String mode =  Validator.getString(
                    Validator.sc, "save/load: ");
            
            if ( mode.equals( "save" ) ) {
                employee.address = "Address of " + employee.name;
                employee.SSN = 10000000 + id;
                employee.ID = id;
                // current directory is NetBeans
                // project home dir
                employee.saveToFile("data/"+fileName+".txt");

                employee.name = null;
                employee.address = null;
                employee.SSN = 0;
                employee.ID = 0;
            } else if ( mode.equals( "load" ) ) {

                employee.loadFromFile("data/"+fileName+".txt");

                System.out.println("After loading from file:");
                System.out.println(employee.name);
                System.out.println(employee.address);
                System.out.println(employee.SSN);
                System.out.println(employee.ID);
            } else {
                System.out.println("Sorry, bad command");
            }
        }
    }

}