import java.util.*;

public class Lecturer {
    public Lecturer() {}

    public Lecturer (String aname, String aid) {
	name = aname; 
	id = aid;
    }

    public void interact(java.io.BufferedReader d) 
	throws java.io.IOException {
	String str = "You teach " + modules.size() + " modules:\n";
	Module m;
	Iterator i = modules.iterator();
	while (i.hasNext()) {
	    m = (Module)i.next();
	    str = str + m.name + "\n";
	}
	str = str + "Module name:\n";
	System.out.print(str);
	String name = d.readLine();
	m = Registry.getModule(name);
	if (null == m) {
	    System.out.println ("Not a module!");
	} else {
	    String menu = "Enter:\n" + "0 to list students\n";
	    if (m.isUpToDate()) {
		menu = menu + "1 to check out module description\n";
	    } else {
		menu = menu + "1 to check in module description\n";
	    }
	    System.out.print (menu);
	    int entry = Integer.parseInt(d.readLine());
	    switch(entry) {
	    case 0: 
		m.makeStudentList();
		break;
	    case 1: 
		if (m.isUpToDate()) {
		    m.checkOutDescription(this);
		} else {
		    System.out.println 
			("Enter new description (one line!):\n"); 
		    m.checkInDescription(this, d.readLine());
		}
		break;
	    default:
		System.out.println ("Unrecognised option");
	    }
	}
    }

    public boolean validate(String trial) {
	return (trial.equals(id));
    }

    // pre: m already has this Lecturer listed as its lecturer
    // post: this Lecturer's records also show it teaching the module
    public void teachModule(Module m) {
	modules.add(m);
    }

    protected HashSet modules = new HashSet();
    public String name;
    public String id;
}
