import java.util.*;
class Person1
{
protected String name;
protected int age;
protected static int count=0;
public Person1(String name,int age)
{
this.set(name);
this.set(age);
}
public Person1(String name)
{
this(name,0);
}
public Person1()
{
this("姓名未知",0);
}
public Person1(Person1 p1)
{
this(p1.name,p1.age);
}
public void finalize()
{
System.out.println("释放对象("+this.toString()+")");
this.count--;
}
public void set(String name)
{
if(name==null||name=="")
this.name="姓名未知";
else
this.name=name;
}
public void set(int age)
{
if(age>0&&age<100)
this.age=age;
else
this.age=0;
}
public void set(String name,int age)
{
this.set(name);
this.set(age);
}
public void set(Person1 p1)
{
this.set(p1.name);
this.set(p1.age);
}
public String getName()
{
return this.name;
}
public int getAge()
{
return this.age;
}
public static void howMany()
{
System.out.println("Person1.count="+count+" ");
}
public String belongClassName()
{
String str="";
if(this instanceof Person1)
str="Person1";
return str;
}
public String toString()
{
return this.name+","+this.age+"岁";
}
public void print()
{
this.howMany();
System.out.println(this.belongClassName()+"类("+this.toString()+")");
}
public int olderThen(Person1 p2)
{
return this.age-p2.age;
}
public boolean equals(Object obj)
{
if(this==obj)
{
return true;
}
if(obj instanceof Person1)
{
Person1 p1=(Person1)obj;
return this.name.equals(p1.name)&&this.age==p1.age;
}
return false;
}
}
class Teacher extends Person1
{
static String major,prof;
public static int[] count={0,0,0,0,0,0,0};
public Teacher(String name,int age,String major,String prof)
{
super(name,age);
this.major=major;
this.prof=prof;
count[0]++;
}
public void how_Many()
{
if(this.major.equals("计算机"))count[1]++;
else if(this.major.equals("数学"))count[2]++;
else if(this.major.equals("英语"))count[3]++;
if(this.prof.equals("讲师"))count[4]++;
else if(this.prof.equals("副教授"))count[5]++;
else if(this.prof.equals("教授"))count[6]++;
}
public void print()
{
System.out.println("计算机专业教师有:"+count[1]+"人");
System.out.println("数学专业教师有:"+count[2]+"人");
System.out.println("英语专业教师有:"+count[3]+"人");
System.out.println("职称为讲师的教师有:"+count[4]+"人");
System.out.println("职称为副教授的教师有:"+count[5]+"人");
System.out.println("职称为教授的教师有:"+count[6]+"人");
System.out.println("教师总人数为:"+count[0]+"人");
}
public String belongClassName()
{
String str="";
if(this instanceof Teacher)
str="Teacher";
return str;
}
public void finalize()
{
System.out.println("释放对象("+this.toString()+")");
if(this.major.equals("CS"))count[1]--;
else if(this.major.equals("MA"))count[2]--;
else if(this.major.equals("EN"))count[3]--;
if(this.prof.equals("TEA1"))count[4]--;
else if(this.prof.equals("TEA2"))count[5]--;
else if(this.prof.equals("TEA2"))count[6]--;
this.count[0]--;
}
public String toString()
{
return this.name+","+this.age+"岁"+","+this.major+"专业"+","+this.prof;
}
}
class Student extends Person1
{
public static int[]count={0,0,0,0};
String major,klass;
int mark;
public Student(String name,int age,String major,String klass,int mark)
{
super(name,age);
this.major=major;
this.klass=klass;
this.mark=mark;
count[0]++;
}
public void how_Many()
{
if(this.major.equals("CS"))count[1]++;
else if(this.major.equals("MA"))count[2]++;
else if(this.major.equals("EN"))count[3]++;
}
public void print()
{
System.out.println("计算机专业学生有:"+count[1]+"人");
System.out.println("数学专业学生有:"+count[2]+"人");
System.out.println("英语专业学生有:"+count[3]+"人");
System.out.println("学生总人数为:"+count[0]+"人");
}
public String belongClassName()
{
String str="";
if(this instanceof Student)
str="Student";
return str;
}
public void finalize()
{
System.out.println("释放对象("+this.toString()+")");
if(this.major.equals("计算机"))count[1]--;
else if(this.major.equals("数学"))count[2]--;
else if(this.major.equals("英语"))count[3]--;
this.count[0]--;
}
public String toString()
{
return this.name+","+this.age+"岁"+","+this.major+"专业"+","+this.klass+"班"+","+this.mark+"分";
}
}
public class TestPer
{
static int m=0,n=0;
static Student[] student=new Student[100];
static Teacher[] teacher=new Teacher[100];
static String name,prof,major,klass;
static int age,mark;
static Scanner scan=new Scanner(System.in);
static void operCh(int i)
{
int x;
}
static void printCh()
{
System.out.println("请选择您欲进行的操作:");
System.out.println("1.输入学生信息 ");
System.out.println("2.输入教师信息 ");
System.out.println("3.删除学生信息 ");
System.out.println("4.删除教师信息");
System.out.println("0.退出系统 ");
}
static void printRes(Student s1)
{
s1.how_Many();
s1.print();
}
static void printRet(Teacher t1)
{
t1.how_Many();
t1.print();
}
public static void main(String args[])
{
int i;
do{ printCh();
i=scan.nextInt();
switch(i)
{
case(0):
break;
case(1):
System.out.println("请分别输入学生的姓名、年龄、专业、班级和成绩!");
name=scan.next();
age=scan.nextInt();
major=scan.next();
klass=scan.next();
mark=scan.nextInt();
student[m]=new Student(name,age,major,klass,mark);
printRes(student[m]); m++;
break;
case(2):
System.out.println("请分别输入教师的姓名、年龄、专业和职称!");
name=scan.next();
age=scan.nextInt();
major=scan.next();
prof=scan.next();
teacher[n]=new Teacher(name,age,major,prof);
printRet(teacher[n]);
n++;
break;
case(3):
System.out.println("请输入要删除的学生编号!");
int no=scan.nextInt()-1;
student[no].finalize();
m--;
System.out.println("完成!");
break;
case(4):
System.out.println("请输入要删除的教师编号!");
int mo=scan.nextInt()-1;
teacher[mo].finalize();
n--;
System.out.println("完成!");
break;
}
}while(i!=0);
System.out.println("谢谢您的使用!");
}
}