//Nathan Viniconis
//CSE230 - UCONN
//12-2001

//Code to control the server..

import java.util.*;
import javax.swing.*;
import java.lang.*;
import java.io.*;
import java.net.*;

public class ServerA3	{
	public static void main (String[] args )	{
		BufferedReader InputMes = new BufferedReader(new InputStreamReader(System.in));
		String Rmessage = "";
		FDataBase FacList = new FDataBase();
		CDataBase CorCat = new  CDataBase("CourseCat.dat");
		CDataBase NewSem = new CDataBase("NewSem.dat");
		CDataBase OldSem = new CDataBase("OldSem.dat");
		SDataBase StuList = new SDataBase();

		Admin TheAdmin= new Admin(FacList,CorCat,NewSem,OldSem,StuList);

		new AcceptConn(FacList,CorCat,NewSem,OldSem,StuList).start();

		TheAdmin.Control();
		System.exit(0);
	}
}

class Admin {

	private FDataBase FacList;
	private CDataBase CorCat;
	private CDataBase NewSem;
	private CDataBase OldSem;
	private SDataBase StuList;
	private BufferedReader InputMes;

	Admin(FDataBase FacListIN,CDataBase CorCatIN,CDataBase NewSemIN,CDataBase OldSemIN,SDataBase StuListIN)	{
		FacList = FacListIN;
		CorCat = CorCatIN;
		NewSem = NewSemIN;
		OldSem = OldSemIN;
		StuList = StuListIN;
		InputMes = new BufferedReader(new InputStreamReader(System.in));
	}

	public void Control()	{
		String Rmessage="";
		boolean done;
		int i,write=1;

		Faculty curFac = new Faculty();
		System.out.println("EXIT:ADDFAC:ASDH:LISTFAC:*NEWSEM*:LISTCORCAT:LISTNEWSEM:*LISTOLDSEM*:ADDSTU:LISTSTU");
		while(!Rmessage.equals("EXIT"))	{
			try	{
				Rmessage = InputMes.readLine();

				if(Rmessage.equals("ADDFAC"))	{
					AddFaculty();
				}
				if(Rmessage.equals("ASDH") )	{
					AssignDH();
				}
				if(Rmessage.equals("LISTFAC") )	{
					ListFac();
				}
				if(Rmessage.equals("NEWSEM") )	{
					//NewSemester();
				}
				if(Rmessage.equals("LISTCORCAT") )	{
					ListCor(1);
				}
				if(Rmessage.equals("LISTNEWSEM") )	{
					ListCor(2);
				}
				if(Rmessage.equals("LISTOLDSEM") )	{
					//ListCor(3);
				}
				if(Rmessage.equals("ADDSTU") )	{
					AddStudent();
				}
				if(Rmessage.equals("LISTSTU") )	{
					ListStudent();
				}
			} catch(Exception e)	{  System.out.println(e); }
		}
		FacList.CloseFac();
	}

	private void ListStudent()	{
		int i=0;
		Vector Stus = new Vector(20,5);
		Student curStu = new Student();
		try	{
			Stus = StuList.GetStudent("list");
			System.out.println("The Current Students: ");
			i=Stus.size()-1;
			while(i>=0)
			{
				curStu = (Student)Stus.get(i);
				System.out.print("ID: " + curStu.ID+ "    LastName: "+curStu.Lname+" FirstName: "+curStu.Fname +
						" Advisor: "+ curStu.Advisor + " Pass: " + curStu.Password );
				if(curStu.TypeStudent)
					System.out.println(" Grad: Y");
				else
					System.out.println(" Grad: N");
				i--;
			}
		} catch(Exception e) { System.out.print(""); }
	}



	private void AddStudent()	{
		String Rmessage;
		Vector Stus = new Vector(20,5);
		Student insert = new Student();
		Student curStu;
		int i = 0, write = 1;

		Stus = StuList.GetStudent("list");
		try{
			System.out.print("What is the ID of the Student?==>");
			insert.ID = InputMes.readLine();
			System.out.print("What is the Last name of the Student?==>");
			insert.Lname = InputMes.readLine();
			System.out.print("\nWhat is the First name of the Student?==>");
			insert.Fname = InputMes.readLine();
			System.out.print("\nWhat Password should this Student have?==>");
			insert.Password = InputMes.readLine();
			System.out.print("Is this student an Undergrad(y/n)?==>");
			Rmessage = InputMes.readLine();
			if(Rmessage.startsWith("y") || Rmessage.startsWith("Y") )	{
				insert.TypeStudent = false;
			}
			else	{
				insert.TypeStudent = true;
			}

			i=Stus.size()-1;
			while(i>=0) {
			curStu = (Student)Stus.get(i);
			if(curStu.ID.equals(insert.ID)) {
					write = 0;
				}
				i--;
			}
			if(write == 1)
				StuList.AddStudent(insert);
			else
				System.out.println("Student already exists");
		} catch(Exception e)	{  System.out.println(e); }
	}


	private void ListCor(int which)	{
		int i=0;
		Vector Cors = new Vector(20,5);
		Course curCor = new Course();
		try	{
			if(which==1)	{ Cors = CorCat.GetCourse("list"); }
			if(which==2)	{ Cors = NewSem.GetCourse("list"); }
			if(which==3)	{ Cors = OldSem.GetCourse("list"); }
			System.out.println("The Current Courses: ");
			i=Cors.size()-1;
			while(i>=0)
			{
				curCor = (Course)Cors.get(i);
				System.out.println("ID: "+curCor.ID + "   Dept: " + curCor.Dept + " Teach: " + curCor.Teacher + "Grad: " + curCor.TypeCourse);
				i--;
			}
		} catch(Exception e) { System.out.print(""); }
	}


	private void NewSemester()	{
		String Rmessage;
		Vector Cor0 = new Vector(20,5);		//For CorCat.
		Vector Cor1 = new Vector(20,5);		//For NewSem.
		Vector Cor2 = new Vector(20,5);		//For OldSemm
		Course insert = new Course();
		Course curCor = new Course();
		int i=0;
		int j,k,l;
		while(CorCat.Writing || NewSem.Writing)	{}

	try{
		Cor0 = CorCat.GetCourse("list");
		Cor1 = NewSem.GetCourse("list");
		Cor2 = OldSem.GetCourse("list");
		insert.ID="XXX";
		insert.Dept="XXX";
		OldSem.AddCourse(insert);
		NewSem.AddCourse(insert);

		j=Cor2.size();
		while(i<j)	{    //Clears OldSem;
			curCor = (Course)Cor2.get(i);
			//System.out.println("Coure being removed from OldSem: " + curCor.ID);
			OldSem.RemCourse(curCor);
			i++;
		}
		i=0;
		k =Cor1.size();
		while(i<k)	{    //Clears New Semester
			curCor = (Course)Cor1.get(i);
			//System.out.println("Coure being removed from NewSem: " + curCor.ID);
			NewSem.RemCourse(curCor);
			i++;
		}

/*		NewSem.DelFile();
		OldSem.DelFile(); */
		//System.out.print("deleted, hit enter:");
		//Rmessage = InputMes.readLine();
		k =Cor1.size();
		i=0;
		while(i<k)	{	//Puts NewSem into OldSem
			curCor = (Course)Cor1.get(i);
			//System.out.println("Coure being added into OldSem: " + curCor.ID);
			OldSem.AddCourse(curCor);
			i++;
		}
		i=0;
		l = Cor0.size();
		while(i<l)	{	//Puts Course Cat into NewSemester
			curCor = (Course)Cor0.get(i);
			//System.out.println("Coure being added into NewSem: " + curCor.ID);
			NewSem.AddCourse(curCor);
			i++;
		}
	}catch(Exception e) { System.out.print("ooo"); }
	}




	private void ListFac()	{
		int i=0;
		Vector Facs = new Vector(20,5);
		Faculty curFac = new Faculty();
		try	{
			Facs = FacList.GetFaculty("list");
			System.out.println("The Current Faculty: ");
			i=Facs.size()-1;
			while(i>=0)
			{
				curFac = (Faculty)Facs.get(i);
				System.out.print("LastName: "+curFac.Lname+" FirstName: "+curFac.Fname +
					" Dept: " +curFac.Dept + " Pass: " + curFac.Password );
				if(curFac.TypeFaculty)
					System.out.println(" DH: Y");
				else
					System.out.println(" DH: N");
				i--;
			}
		} catch(Exception e) { System.out.print(""); }
	}


	private void AssignDH()	{
		Vector Facs = new Vector(20,5);
		Faculty insert = new Faculty();
		Faculty curFac = new Faculty();
		Faculty DHfac = new Faculty();
		int i = 0, write = 1;

		Facs = FacList.GetFaculty("list");

		try	{
			System.out.print("What is the Last name of the Faculty?==>");
			insert.Lname = InputMes.readLine();

			i=Facs.size()-1;
			while(i>=0) {
				curFac = (Faculty)Facs.get(i);
				if(curFac.Lname.equals(insert.Lname)) {
						write = 0;
						i=-1;
				}
				i--;
			}
			if(write == 1)
				System.out.println("The Faculty Doesn't Exist");
			else	{
				DHfac = curFac;
				DHfac.TypeFaculty = true;
				FacList.RemFaculty(curFac);

				Facs = FacList.GetFaculty("list");

				i=Facs.size()-1;
				while(i>=0) {
					curFac = (Faculty)Facs.get(i);
					if(curFac.Dept.equals(DHfac.Dept)) {
						FacList.RemFaculty(curFac);
						curFac.TypeFaculty = false;
						FacList.AddFaculty(curFac);
					}
					i--;
				}
				FacList.AddFaculty(DHfac);
			}
		} catch(Exception e)	{  System.out.println(e); }
	}


	private void AddFaculty()	{
		Vector Facs = new Vector(20,5);
		Faculty insert = new Faculty();
		Faculty curFac;
		int i = 0, write = 1;

		Facs = FacList.GetFaculty("list");
		try{
			System.out.print("What is the Last name of the Faculty?==>");
			insert.Lname = InputMes.readLine();
			System.out.print("\nWhat is the First name of the Faculty?==>");
			insert.Fname = InputMes.readLine();
			System.out.print("\nWhat is the Department of the Faculty?==>");
			insert.Dept = InputMes.readLine();
			System.out.print("\nWhat Password should this Fac have?==>");
			insert.Password = InputMes.readLine();

			i=Facs.size()-1;
			while(i>=0) {
			curFac = (Faculty)Facs.get(i);
			if(curFac.Lname.equals(insert.Lname)) {
					write = 0;
				}
				i--;
			}
			if(write == 1)
				FacList.AddFaculty(insert);
			else
				System.out.println("Faculty already exists");
		} catch(Exception e)	{  System.out.println(e); }
	}
}


//Handles the Threads which control the connected Clients.//
//														  //
//														  //
//Handles the Threads which control the connected Clients.//
class AcceptConn extends Thread	{

	private FDataBase FacList;
	private CDataBase CorCat;
	private CDataBase NewSem;
	private CDataBase OldSem;
	private SDataBase StuList;


	public AcceptConn(FDataBase FacListIN,CDataBase CorCatIN,CDataBase NewSemIN,CDataBase OldSemIN,SDataBase StuListIN)	{
		FacList = FacListIN;
		CorCat = CorCatIN;
		NewSem = NewSemIN;
		OldSem = OldSemIN;
		StuList = StuListIN;
	}

	public void run()	{
		int Xcount = 1;
		try	{
			ServerSocket s = new ServerSocket(8189);
			while(true)	{
				Socket incoming = s.accept();
				System.out.print("Starting :" + Xcount + ": ");
				new Handler(incoming,Xcount,FacList,CorCat,NewSem,OldSem,StuList).start();
				Xcount++;
			}
		} catch(Exception e)	{  System.out.println(e); }
	}
}

//Handles the Threads which control the connected Clients.//
//														  //
//														  //
//Handles the Threads which control the connected Clients.//
class Handler extends Thread 	{
	private Socket incoming;
	private int counter;
	private FDataBase FacList;
	private CDataBase CorCat;
	private CDataBase NewSem;
	private CDataBase OldSem;
	private SDataBase StuList;
	private ObjectOutputStream out;
	private ObjectInputStream in;

	public Handler(Socket i, int c,FDataBase FacListIn,CDataBase CorCatIN,CDataBase NewSemIN,CDataBase OldSemIN,SDataBase StuListIN)	{
		try	{
			incoming = i;
			out = new ObjectOutputStream(incoming.getOutputStream());
			in = new ObjectInputStream(incoming.getInputStream());
		} catch (Exception e)	{   System.out.println(e);  }
		counter = c;
		FacList = FacListIn;
		CorCat = CorCatIN;
		NewSem = NewSemIN;
		OldSem = OldSemIN;
		StuList = StuListIN;
	}

	public void run()	{
		String str;
		try	{

			str = (String)in.readObject();
			if(str.trim().equals("s"))	{
				System.out.println(" Student Connected.");
				Srun();
				System.out.println("Stopping " + counter + ":Student Disconnected.");
			}
			else if(str.trim().equals("d"))	{
				System.out.println(" Department Head Connected.");
				Drun();
				System.out.println("Stopping :" + counter + ":Department Head Disconnected.");
			}
			else	{
				System.out.println("Some wierdo tried to connect");
				incoming.close();
			}
			incoming.close();
		} catch (Exception e)	{   System.out.println(e);  }
	}

//Handles the Student Client
	public void Srun()	{
		String str = "HATE:LOGON:ADDSEM:LISTSEM:LISTENR:INFO:CHGINFO";
		try	{
			out.writeObject(str);
			SCommunicate();
		}catch (Exception e)	{	System.out.println(e);	}
	}

//Handles the Department Head Client
	public void Drun()	{
		String str;

		try	{
			str = "LOGON:HATE:ADDFAC:LISTFAC:REMFAC:CHGFAC:LISTCAT:LISTSEM:CHGCAT:CHGSEM:ASSIGN";
			out.writeObject(str);
			DCommunicate();
		}catch (Exception e)	{	System.out.println(e);	}
	}

	private void AssignAd()	{
		Vector Stus = new Vector(20,5);
		String strIN = "";
		Student curStu = new Student();
		Student curStu2 = new Student();
		Stus = StuList.GetStudent("list");
		try{
			out.writeObject(Stus);
			curStu = (Student)in.readObject();


			if(!curStu.ID.equals("XXX") )	{
				StuList.RemStudent(curStu);
				curStu.Advisor = "hehe";
				strIN = (String)in.readObject();
				curStu.Advisor = strIN;
				System.out.println("strIN: "+ strIN   +" Advisor: " + curStu.Advisor);
				StuList.AddStudent(curStu);
			}
		}catch (Exception e)	{	System.out.println(e);	}
	}

	private boolean DLogOn()	{
		String Lname="",Pass="";
		Vector Facs = new Vector(20,5);
		Faculty search = new Faculty();
		int find = 0;
		int i = 0;

		try	{
			Lname = (String)in.readObject();
			Pass = (String)in.readObject();
			Facs = FacList.GetFaculty("list");
		}catch (Exception e)	{	System.out.println(e);	}

		i=Facs.size()-1;
		while (i>=0)	{
			search = (Faculty)Facs.get(i);
			if(search.Lname.equals(Lname))	{
				find = 1;
				i = -1;
			}
			i--;
		}
		if(search.Password.equals(Pass) && find == 1)	{
			try	{
				out.writeObject(search);
			}catch (Exception e)	{	System.out.println("DOHAAA");	}
			return(true);
		}
		else	{
			search.Lname = "XXX";
			try {
				out.writeObject(search);
			}catch (Exception e)	{	System.out.println("DOHAAA");	}
			return(false);
		}
	}

	private void AddFaculty()	{
		String Smessage,Rmessage;
		Vector Facs = new Vector(20,5);
		Faculty insert;
		try	{

			Facs = FacList.GetFaculty("list");
			out.writeObject(Facs);
			insert = (Faculty)in.readObject();
			if(insert.Lname.equals("XXX") == false){
				FacList.AddFaculty(insert);
			}
		}catch (Exception e)	{	System.out.println(e);	}
	}

	private void RemFaculty()	{
		String Smessage,Rmessage;
		Vector Facs = new Vector(20,5);
		Faculty insert;
		try	{

			Facs = FacList.GetFaculty("list");
			out.writeObject(Facs);

			insert = (Faculty)in.readObject();
			if(insert.Lname.compareTo("XXX")!=0){
				FacList.RemFaculty(insert);
			}
		}catch (Exception e)	{	System.out.println(e);	}
	}


    private void ListFaculty()	{
		String Smessage, Rmessage;
		Vector Facs = new Vector(20,5);
		try	{
			Facs = FacList.GetFaculty("list");
			out.writeObject(Facs);
		} catch(Exception e) {}
	}

	private void ChangeFaculty()	{
		Vector Facs = new Vector(20,5);
		Faculty insert;
		Faculty curFac = new Faculty();
		int i;
		try	{
			Facs = FacList.GetFaculty("list");
			out.writeObject(Facs);
			insert = (Faculty)in.readObject();

			if(!insert.Lname.equals("XXX") )	{
				i=Facs.size()-1;
				while(i>=0) {
					curFac = (Faculty)Facs.get(i);
					if(curFac.Lname.equals(insert.Lname)) {
						FacList.RemFaculty(curFac);
						FacList.AddFaculty(insert);
					}
					i--;
				}
			}
		}catch (Exception e)	{	System.out.println(e);	}
	}



//Used to communicate the ECHO program with the Clients
	private void DCommunicate()	{
		try	{
			boolean done = false;
			while(!done)	{
				String str = (String)in.readObject();
				String str2="BYEnull";
				if (str == null) { done = true; out.writeObject(str2); }
				else if	(str.trim().equals("HATE") || str.trim().equals("HATE+") )	{
					str2="BYE";
					out.writeObject(str2);
					done = true;
				}
				else if	(str.trim().equals("LOGON"))	{
					str2="LOGON";
					out.writeObject(str2);
					DLogOn();
				}
				else if (str.trim().equals("ADDFAC+")){
					str2="ADDFAC";
					out.writeObject(str2);
					AddFaculty();
				}
				else if (str.trim().equals("LISTFAC+")){
					str2="LISTFAC";
					out.writeObject(str2);
					ListFaculty();
				}
				else if (str.trim().equals("REMFAC+")){
					str2="REMFAC";
					out.writeObject(str2);
					RemFaculty();
				}
				else if (str.trim().equals("CHGFAC+")){
					str2="CHGFAC";
					out.writeObject(str2);
					ChangeFaculty();
				}
				else if (str.trim().equals("LISTCAT+") ){
					str2="LISTCAT";
					out.writeObject(str2);
					ListCourses(true);
				}
				else if (str.trim().equals("LISTSEM+") ) {
					str2="LISTSEM";
					out.writeObject(str2);
					ListCourses(false);
				}
				else if (str.trim().equals("ADDCAT+") ) {
					str2="ADDCAT";
					out.writeObject(str2);
					AddCourse(true);
				}
				else if (str.trim().equals("ADDSEM+") ) {
					str2="ADDSEM";
					out.writeObject(str2);
					AddCourse(false);
				}
				else if (str.trim().equals("CHGCAT+") ) {
					str2="CHGCAT";
					out.writeObject(str2);
					ChangeCourse(true);
				}
				else if (str.trim().equals("CHGSEM+") ) {
					str2="CHGSEM";
					out.writeObject(str2);
					ChangeCourse(false);
				}
				else if (str.trim().equals("REMCAT+") ) {
					str2="REMCAT";
					out.writeObject(str2);
					RemoveCourse(true);
				}
				else if (str.trim().equals("REMSEM+") ) {
					str2="REMSEM";
					out.writeObject(str2);
					RemoveCourse(false);
				}
				else if (str.trim().equals("ASSIGN+") ) {
					str2="ASSIGN";
					out.writeObject(str2);
					AssignAd();
				}
				else	{
					str2="Echo :".concat(str);
					out.writeObject(str2);
				}
			}
		}catch (Exception e)	{	System.out.println(e);	}
	}

	private void RemoveCourse(boolean which)	{
		String Smessage,Rmessage;
		Vector Cors = new Vector(20,5);
		Course insert;
		try	{
			if(which)	{
				Cors = CorCat.GetCourse("list");
			}
			else { Cors = NewSem.GetCourse("list"); }
			out.writeObject(Cors);

			insert = (Course)in.readObject();
			if(insert.ID.compareTo("XXX")!=0){
				if(which)	{
					CorCat.RemCourse(insert);
				}
				else { NewSem.RemCourse(insert); }
			}
		}catch (Exception e)	{	System.out.println(e);	}
	}




	private void ChangeCourse(boolean which)	{
		Vector Cors = new Vector(20,5);
		Course insert;
		Course curCor = new Course();
		int i;
		try	{
			if(which)	{
				Cors = CorCat.GetCourse("list");
			}
			else	{ Cors = NewSem.GetCourse("list");	}
			out.writeObject(Cors);
			insert = (Course)in.readObject();

			if(!insert.ID.equals("XXX") )	{
				i=Cors.size()-1;
				while(i>=0) {
					curCor = (Course)Cors.get(i);
					if(curCor.ID.equals(insert.ID)) {
						if(which)	{
							CorCat.RemCourse(curCor);
							CorCat.AddCourse(insert);
						}
						else	{
							NewSem.RemCourse(curCor);
							NewSem.AddCourse(insert);
						}
					}
					i--;
				}
			}
		}catch (Exception e)	{	System.out.println(e);	}
	}

	private void AddCourse(boolean which)	{
		String Smessage,Rmessage;
		Vector Cors0 = new Vector(20,5);
		Vector Cors1 = new Vector(20,5);
		Course insert;
		try	{
			Cors1 = CorCat.GetCourse("list");
			Cors0 = NewSem.GetCourse("list");
			out.writeObject(Cors1);
			out.writeObject(Cors0);
			insert = (Course)in.readObject();
			System.out.println("***" + insert.Dept);
			if(insert.ID.equals("XXX") == false){
				if(which)	{CorCat.AddCourse(insert); }
				else	{ NewSem.AddCourse(insert); }
			}
		}catch (Exception e)	{	System.out.println(e);	}
	}

	private void ListCourses(boolean which)	{
		Vector Cors = new Vector(20,5);
		try	{
			if(which)	{ Cors = CorCat.GetCourse("list"); }
			else	{ Cors = NewSem.GetCourse("list"); }
			out.writeObject(Cors);
		} catch(Exception e) {}
	}

	private void SCommunicate()	{
		try	{
			boolean done = false;
			while(!done)	{
				String str = (String)in.readObject();
				String str2="BYEnull";
				if (str == null) { done = true; out.writeObject(str2); }
				else if	(str.trim().equals("HATE") || str.trim().equals("HATE+") )	{
					str2="BYE";
					out.writeObject(str2);
					done = true;
				}
				else if	(str.trim().equals("LOGON"))	{
					str2="LOGON";
					out.writeObject(str2);
					SLogOn();
				}
				else if (str.trim().equals("LISTSEM+")){
					str2="LISTSEM";
					out.writeObject(str2);
					ListCourses(false);
				}
				else if (str.trim().equals("ADDSEM+")){
					str2="ADDSEM";
					out.writeObject(str2);
					SAddSem();
				}
				else if (str.trim().equals("LISTENR+")){
					str2="LISTENR";
					out.writeObject(str2);
				}
				else if (str.trim().equals("REMSEM+")){
					str2="REMSEM";
					out.writeObject(str2);
					SREMsem();
				}
				else if (str.trim().equals("INFO+")){
					str2="INFO";
					out.writeObject(str2);
				}
				else if (str.trim().equals("CHGINFO+")){
					str2="CHGINFO";
					out.writeObject(str2);
					CHGInfo();
				}
				else	{
					str2="Echo :".concat(str);
					out.writeObject(str2);
				}
			}
		}catch (Exception e)	{	System.out.println(e);	}
	}

	private void CHGInfo()	{
		Student curStu = new Student();
		try{
			curStu = (Student)in.readObject();
			StuList.RemStudent(curStu);
			curStu = (Student)in.readObject();
			StuList.AddStudent(curStu);
		}catch(Exception e) { System.out.println(e); }
	}


	private void SREMsem()	{
		Student theone = new Student();
		Student theone2 = new Student();
		try{
			theone = (Student)in.readObject();
			theone2 = (Student)in.readObject();
			if(!theone.ID.equals("XXX") )	{
				StuList.RemStudent(theone);
				StuList.AddStudent(theone);
			}
		}catch (Exception e)	{	System.out.println(e);	}
	}

	private void SAddSem()	{
		Vector Cors = new Vector(20,5);
		Vector Stus = new Vector(20,5);
		int i = 0;
		Student theone = new Student();
		Student theone2 = new Student();
		Cors = NewSem.GetCourse("list");
		try	{
			out.writeObject(Cors);

			theone = (Student)in.readObject();

			theone2 = (Student)in.readObject();

			System.out.println("TheIncomingThing *" + theone2.courseName[0] );
			if(!theone2.ID.equals("XXX") )	{

				StuList.RemStudent(theone);
				StuList.AddStudent(theone2);
			}
		}catch (Exception e)	{	System.out.println(e);	}
	}




	private boolean SLogOn()	{
		String ID="",Pass="";
		Vector Stus = new Vector(20,5);
		Student search = new Student();
		int find = 0;
		int i = 0;

		try	{
			ID = (String)in.readObject();
			Pass = (String)in.readObject();
			Stus = StuList.GetStudent("list");
		}catch (Exception e)	{	System.out.println(e);	}

		i=Stus.size()-1;
		while (i>=0)	{
			search = (Student)Stus.get(i);
			if(search.ID.equals(ID))	{
				find = 1;
				i = -1;
			}
			i--;
		}
		if(search.Password.equals(Pass) && find == 1)	{
			try	{
				out.writeObject(search);
			}catch (Exception e)	{	System.out.println("DOHAAA");	}
			return(true);
		}
		else	{
			search.ID = "XXX";
			try {
				out.writeObject(search);
			}catch (Exception e)	{	System.out.println("DOHAAA");	}
			return(false);
		}
	}
}