编写java程序 学生类和测试类

2025-03-09 12:32:20
推荐回答(1个)
回答1:

import java.util.LinkedList;

public class StudentTest {
static LinkedList sl;
public static void main(String[] args) {
sl = new LinkedList();
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;
}
}