📄 work.java
字号:
{
System.out.println(" no records exists or id not exists!");
return;
}
}
//delete all member
public void delAll(String strInfo)
{
if(studTable.size()>0)studTable.clear() ;
if(empTable.size()>0) empTable.clear() ;
}
//List Member by ID
public void listbyID(String strInfo)
{
String strTemp = strInfo;
int pos = strTemp.indexOf(" ");
strTemp = trim(strTemp.substring(pos+1,strTemp.length()));
if(strTemp.equals(""))
{
System.out.println("bad input id number! ");
return;
}
String strID= strTemp;
person ps = new person();
if(studTable.containsKey(strID))
{
// can present mutil
ps =(studInfo) studTable.get(strID);
}else if(empTable.containsKey(strID))
{
ps = (empInfo)empTable.get(strID);
}else
{
System.out.println("ID number "+ "\"strID\"" +" not exists!");
return;
}
System.out.println("ID number"+strID);
ps.display() ;
}
public void listStaff(String strInfo)
{
int i=0;
for (Enumeration e = empTable.keys(); e.hasMoreElements() ;)
{
String strID = (String)e.nextElement() ;
if(strID.startsWith("staff"))
{
empInfo ei= (empInfo)empTable.get(strID);
System.out.println("ID number:"+strID);
ei.display() ;
i++;
}
}
if(i==0) {System.out.println("no staff in recordset");}
else{System.out.println("staff:"+i); }
}
//list teacher
public void listAcad(String strInfo)
{
int i=0;
for (Enumeration e = empTable.keys(); e.hasMoreElements() ;)
{
String strID = (String)e.nextElement() ;
if(strID.startsWith("acad"))
{
acadInfo ai= (acadInfo)empTable.get(strID);
System.out.println("ID number:"+strID);
ai.display() ;
i++;
}
}
if(i==0) {System.out.println("no acad in recordset");}
else{System.out.println("acad:"+i); }
}
//list students
public void listStud(String strInfo)
{
int i=0;
for (Enumeration e = studTable.keys(); e.hasMoreElements() ;)
{
String strID = (String)e.nextElement() ;
studInfo si= (studInfo)studTable.get(strID);
System.out.println("ID number:"+strID);
si.display() ;
i++;
}
if(i==0) {System.out.println("no student in recordset");}
else{System.out.println("student counted:"+i); }
}
//list all member
public void listAll(String strInfo)
{
listStud(strInfo);
listAcad(strInfo);
listStaff(strInfo);
}
//create new subject
public void create_subject(String strInfo)
{
String strTemp = strInfo;
int pos = strTemp.indexOf(" ");
strTemp = trim(strTemp.substring(pos+1,strTemp.length()));
StringTokenizer st = new StringTokenizer(strTemp,",");
if(st.countTokens()<2)
{
System.out.println("bad input subject information! ");
return;
}
String subjectNum = st.nextToken();
subjectInfo si =new subjectInfo();
si.setSubject_title(st.nextToken() );
si.setPrereq("");
subjectTable.put(subjectNum,si);
}
//enroll a subject to student
public void enrol(String strInfo)
{
String strTemp = strInfo;
int pos = strTemp.indexOf(" ");
strTemp = trim(strTemp.substring(pos+1,strTemp.length()));
StringTokenizer st = new StringTokenizer(strTemp,":");
if(st.countTokens()<2)
{
System.out.println("bad input enrolling information! ");
return;
}
String studNum = st.nextToken() ;
String subject_code = st.nextToken() ;
studInfo si = (studInfo)studTable.get(studNum);
if(si!=null)
{
System.out.println("bad input student code! ");
return;
}else
{
if(!si.getSubject_code().equals(""))
{
si.setSubject_code(subject_code);
}else
{
System.out.println("student "+ studNum +" has been enrolled one subject! ");
return;
}
}
}
//unenroll a studen
public void unenrol(String strInfo)
{
String strTemp = strInfo;
int pos = strTemp.indexOf(" ");
strTemp = trim(strTemp.substring(pos+1,strTemp.length()));
StringTokenizer st = new StringTokenizer(strTemp,":");
if(st.countTokens()<2)
{
System.out.println("bad input information! ");
return;
}
String studNum = st.nextToken() ;
String subject_code = st.nextToken() ;
studInfo si = (studInfo)studTable.get(studNum);
if(si!=null)
{
System.out.println("bad input student number! ");
return;
}else
{
if(si.getSubject_code().equals(subject_code))
{
si.setSubject_code("");
}else
{
System.out.println("student "+ studNum +" is not been enrolled "+subject_code);
return;
}
}
}
// assign a acad to a subject
public void assign(String strInfo)
{
String strTemp = strInfo;
int pos = strTemp.indexOf(" ");
strTemp = trim(strTemp.substring(pos+1,strTemp.length()));
StringTokenizer st = new StringTokenizer(strTemp,":");
if(st.countTokens()<2)
{
System.out.println("bad input enrolling information! ");
return;
}
String acadNum = st.nextToken() ;
String subject_code = st.nextToken() ;
acadInfo ai = (acadInfo)empTable.get(acadNum);
if(ai!=null)
{
System.out.println("bad input acad code! ");
return;
}else
{
if(!ai.getSubject_code().equals(""))
{
ai.setSubject_code(subject_code);
}else
{
System.out.println("student "+ acadNum +" has been enrolled one subject! ");
return;
}
}
}
// unassign a acad to a subject
public void unassign(String strInfo)
{
String strTemp = strInfo;
int pos = strTemp.indexOf(" ");
strTemp = trim(strTemp.substring(pos+1,strTemp.length()));
StringTokenizer st = new StringTokenizer(strTemp,":");
if(st.countTokens()<2)
{
System.out.println("bad input information! ");
return;
}
String acadNum = st.nextToken() ;
String subject_code = st.nextToken() ;
acadInfo ai = (acadInfo)empTable.get(acadNum);
if(ai!=null)
{
System.out.println("bad input acad number! ");
return;
}else
{
if(ai.getSubject_code().equals(subject_code))
{
ai.setSubject_code("");
}else
{
System.out.println("student "+ acadNum +" is not been enrolled "+subject_code);
return;
}
}
}
//set subject prerequisites
public void set_prereq(String strInfo)
{
String strTemp = strInfo;
int pos = strTemp.indexOf(" ");
strTemp = trim(strTemp.substring(pos+1,strTemp.length()));
StringTokenizer st = new StringTokenizer(strTemp,":");
if(st.countTokens()<2)
{
System.out.println("bad input prerequisites information! ");
return;
}
String subject_code = st.nextToken() ;
String pre_subject_code = st.nextToken() ;
subjectInfo si = (subjectInfo)subjectTable.get(subject_code);
if(si!=null)
{
System.out.println("bad input subject code! ");
return;
}else
{
si.setPrereq(pre_subject_code);
}
}
//get subject prerequisites
public void get_prereqs(String strInfo)
{
String strTemp = trim(strInfo);
int pos = strTemp.indexOf(" ");
if(pos<=0)
{
System.out.println("bad input command! ");
return;
}
String subject_code = trim(strTemp.substring(pos+1,strTemp.length()));
subjectInfo si = (subjectInfo)subjectTable.get(subject_code);
if(si!=null)
{
System.out.println("bad input subject code! ");
return;
}else
{
if(si.getPrereq().equals(""))
{
System.out.println("subject "+subject_code+" has no any prerequisites ");
}
else
{System.out.println(si.getPrereq() );}
}
}
//count staff
public void count_staff()
{
System.out.println("COUNT STAFF:"+this.fun_count_staff());
}
private int fun_count_staff()
{
int i=0;
for (Enumeration e = empTable.keys(); e.hasMoreElements() ;)
{
String strID = (String)e.nextElement() ;
if(strID.startsWith("staff"))
{
i++;
}
}
return i;
}
public void count_employee()
{
System.out.println("COUNT EMPLOYEES:"+empTable.size());
}
public void count_acad()
{
System.out.println("COUNT EMPLOYEES:"+(empTable.size()-this.fun_count_staff()) );
}
public void count_student()
{
System.out.println("COUNT STUDENTS:"+studTable.size() );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -