⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 work.java

📁 一个用JAVA编写的学生管理系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
       }
       public void count_all()
       {
         System.out.println("COUNT ALL:"+(studTable.size()+empTable.size()));
       }

	public String getCommand(String txtCommand)
	{
		String strTemp = lTrim(txtCommand);
		int pos = strTemp.indexOf(" ");
		if(pos>0)
			return strTemp.substring(0,pos+1);
		else
			return strTemp;
	}
/************************
function lTrim(String str)

************************/
public static String lTrim(String strTemp)
{
	int  iCount, iLength;

	String sTemp = strTemp;

	iLength = sTemp.length();
	for (iCount = 0; iCount < iLength; iCount++)
		if (sTemp.charAt(iCount) !=' ' )
			return sTemp.substring(iCount, iLength);

	return "";
}

public static String  rTrim(String strTemp)
{
	int iCount, iLength;

	String sTemp = strTemp;
	iLength = sTemp.length();
	for(iCount = iLength - 1; iCount >= 0; iCount--)
		if (sTemp.charAt(iCount) != ' ')
			return sTemp.substring(0, iCount + 1);

	return "";
}


public static String  trim(String strTemp)
{
	return rTrim(lTrim(strTemp));
}

//if data file not exists ,then create new ,else read data from files
public static boolean processData()
{
  if(!readDataFromFile("studInfo.dat")) return false;
  if(!readDataFromFile("empInfo.dat")) return false;
  if(!readDataFromFile("subjectInfo.dat")) return false;
  return true;
}

public static boolean readDataFromFile(String file_name)
{
       File studFile = new File(file_name);

        boolean ret = true;
        if(!studFile.exists())
        {
          try{
                ret = studFile.createNewFile();
          }catch(IOException ex)
          {
            System.out.println("create new file err: "+ex.toString() );
            return false;
          }

          if(!ret) return false;

        }
        else
        {
                try
                {
                        ObjectInputStream in = new ObjectInputStream(new FileInputStream(file_name));
                      if(in!=null)
                      {
                        if(file_name.startsWith("stud"))
                        {
                          studTable = (Hashtable)in.readObject();
                        }
                        else if(file_name.startsWith("emp"))
                        {
                          empTable = (Hashtable)in.readObject();
                        }
                        else
                        {
                          subjectTable = (Hashtable)in.readObject();
                        }

                        in.close();
                      }else
                      {
                        System.out.println("read data from file "+ file_name );
                        return false;
                      }

                }catch(Exception ex)
                {
                        System.out.println("read file "+ file_name + " err: "+ ex);
                        return false;
                }
        }

        return true;

}


//internal call
//super class
public class person implements Serializable
{
        protected String surname;
        protected String given_name;
        protected String email;
        protected String date_of_birth;
        protected String telephone;

        public String getSurname()
        {
          return this.surname ;
        }
        public void setSurname(String _surname)
        {
          if(!_surname.equals("")&&_surname!=null) this.surname = _surname;
        }

        public String getGiven_name()
        {
          return this.given_name ;
        }
        public void setGiven_name(String _given_name)
        {
          if(!_given_name.equals("")&&_given_name!=null)
            this.given_name = _given_name;
        }

        public String getEmail()
       {
         return this.email  ;
       }
       public void setEmail(String _email)
       {
         if(!_email.equals("")&&_email!=null)
           this.email  = _email;
        }

        public String getDate_of_birth()
        {
          return this.date_of_birth  ;
        }
        public void setDate_of_birth(String birth_date)
        {
          if(!birth_date.equals("")&&birth_date!=null)
          this.date_of_birth = birth_date;
        }

       public String getTelephone()
       {
                return this.telephone ;
       }
       public void setTelephone(String _telephone)
       {
             if(!_telephone.equals("")&&_telephone!=null)
                this.telephone  = _telephone;
       }

       public void display()
       {
         System.out.println("surname:"+this.surname );
         System.out.println("given name:"+this.given_name );
         System.out.println("email:" + this.email );
         System.out.println("date of birth:"+this.date_of_birth );
         System.out.println("telephone:"+ this.telephone );
       }

}
//student class
public class studInfo extends person implements Serializable
{
        protected String subject_code;

        public String getSubject_code()
        {
          if(this.subject_code!=null )
            return this.subject_code  ;
          else
            return "";
        }
        public void setSubject_code(String _subject_code)
        {

           this.subject_code  = _subject_code;
        }
        public void display()
        {
          super.display();
          System.out.println("subject code:"+ this.subject_code );
        }

}
//employee class
public class empInfo extends person implements Serializable
{
     protected String salary;
      public String getSalary()
     {
        return this.salary ;
     }
     public void setSalary(String _salary)
     {
        if(!_salary.equals("")&&_salary!=null)
        this.salary  = _salary;
     }

     public void display()
       {
         super.display();
         System.out.println("salary:"+ this.salary  );
        }
}
// teacher class
public class acadInfo extends empInfo implements Serializable
{
        protected String subject_code;

        public String getSubject_code()
        {
         if(this.subject_code!=null )
          return this.subject_code  ;
         else
           return "";
        }
        public void setSubject_code(String _subject_code)
        {

           this.subject_code  = _subject_code;
        }
        public void display()
        {
          super.display();
          System.out.println("subject code:"+ this.subject_code );
        }
}


public class subjectInfo implements Serializable
{
        //protected String subject_code;
        protected String subject_title;
        protected String prereq;
     //   public String getSubject_code()
    //   {
    //      return this.subject_code  ;
    //   }
  //     public void setSubject_code(String _subject_code)
  //     {
  //        this.subject_code  = _subject_code;
  //      }
        public String getSubject_title()
       {
          if(this.subject_title!=null )
            return this.subject_title  ;
          else
            return "";
       }
       public void setSubject_title(String _subject_title)
       {
          this.subject_title  = _subject_title;
        }

        public String getPrereq()
      {
        if(this.prereq != null)
          return this.prereq  ;
        else
          return "";
      }
      public void setPrereq(String _prereq)
      {
         this.prereq  = _prereq;
      }
}

public static int getCommIndex(String strComm)
{
  String[] command = new String[24];
  command[0]="ADD_STUDENT";
  command[1]="ADD_EMPLOYEE";
  command[2]="EDIT_STUDENT";
  command[3]="EDIT_EMPLOYEE";
  command[4]="DEL";
  command[5]="DEL_ALL";
  command[6]="LIST";
  command[7]="LIST_STAFF";
  command[8]="LIST_ACADEMICS";
  command[9]="LIST_STUDENTS";
  command[10]="LIST_ALL";
  command[11]="SAVE";
  command[12]="CREATE_SUBJECT";
  command[13]="ENROL";
  command[14]="UNENROL";
  command[15]="ASSIGN";
  command[16]="UNASSIGN";
  command[17]="SET_PREREQ";
  command[18]="GET_PREREQS";
  command[19]="COUNT_STAFF";
  command[20]="COUNT_ACADEMICS";
  command[21]="COUNT_STUDENTS";
  command[22]="COUNT_EMPLOYEES";
  command[23]="COUNT_ALL";
  command[24]="";
  boolean find=false;
 // return -1;
  int i=0;
  for( ;i<command.length ;i++)
  {
    if(strComm.equals(command[i]))
   {
    find = true;

    return i;

   }
  }
  return -1;

}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -