class DataBase//数据库类
{
static String [] stu=new String[10];
public void store(String name)
{
if (checkRepeat(name))
{
return ;
}
stu[checknonull()]=name;
}
public int checknonull()
{
int num=0;
for (int i=0;i<=stu.length-1 ;i++ )
{
if (stu[i]==null)
{
num=i;
}
}
return num;
}
public boolean checkRepeat(String name)
{
boolean tag=false;
for (int i=0;i<=stu.length-1 ;i++ )
{
if (name.equals(stu[i]))
{
tag=true;
}
}
return tag;
}
public String toString()
{
String str="";
for (int i=0;i<=stu.length-1 ;i++ )
{
str=str+stu[i]+",";
}
return str;
}
}
class Student //学生类
{
String name;
String id;
int age;
Student(String name,String id,int age)
{
this.name=name;
this.id=id;
this.age=age;
}
public static DataBase createDataBase()
{
DataBase data=new DataBase();
return data;
}
public String getName()
{
return this.name;
}
}
class Demo3
{
public static void main(String args[])
{
DataBase data=Student.createDataBase();
data.store( new Student("weige","3444",34).getName());
data.store( new Student("weige","3444",34).getName());
data.store( new Student("weige","3444",34).getName());
data.store( new Student("weige","3444",34).getName());
System.out.println(data.toString());
}
} |
|