编写java程序 学生类和测试类
1个回答
展开全部
import java.util.LinkedList;
public class StudentTest {
static LinkedList<Student> sl;
public static void main(String[] args) {
sl = new LinkedList<Student>();
Student s1 = new Student(1,"aa",12,"bb");
Student s2 = new Student(2,"ae",42,"br");
Student s3 = new Student(3,"ar",52,"fb");
enQueue(s1);//
enQueue(s2);//
enQueue(s3);//进队
deQueue();//出队
}
public static boolean QueueEmpty()//判断队列是否为空
{
return sl.isEmpty();
}
public static void enQueue(Student o)//进队
{
sl.addLast( o);
}
public static Object deQueue()//出队
{
if(!sl.isEmpty())
{
return sl.removeFirst();
}
return "队列为空";
}
}
class Student{
int No;
String name;
int age;
String address;
public Student(int n,String na,int a,String ad){
No = n;
name = na;
age = a;
address = ad;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询