我正在使用PriorityQueue结构来获取用户设置的一些字段,这是代码的一部分:
package gqg;
import java.util.Queue;
public class Student {
//variables (ID, Name, ...), constructors, getters and setters...
Queue<Student> StudentQueue = new PriorityQueue<Student>();
public void Add() { //method to add the student at Queue
for(int x=0; x<1; x++) {
Student st = new Student();
System.out.println("+---------------------------+\n"
+ "| Students Registration |\n"
+ "+---------------------------+");
System.out.println("| Type the student's ID:");
stu.setID(user.nextInt());
System.out.println("| Type the student's name:");
stu.setName(user.next());
System.out.println("| Type the student's age:");
stu.setAge(user.nextInt());
//and other fields...
StudentQueue.add(st);
}
System.out.println("Done. Student has been added successfuly\n"); …Run Code Online (Sandbox Code Playgroud)