Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedList;
- import java.util.PriorityQueue;
- import java.util.Queue;
- import java.util.Scanner;
- import static java.lang.System.out;
- class Queuelab5 {
- public static void main(String[] args) {
- Registration regi = new Registration();
- regi.enterLine();
- regi.enterLine();
- regi.enterLine();
- regi.enterLine();
- regi.enterLine();
- regi.enterLine();
- regi.displayOriginalLine();
- regi.disperseLine();
- regi.exitLine();
- }
- }
- class Registration{
- private PriorityQueue <Student> ogline;
- private Queue<Student> reline;
- class Student implements Comparable{
- private String name;
- private int age;
- public Student(String n, int a)
- {
- name= n;
- age=a;
- }
- public String toString()
- {
- return name+ " " + age + " ";
- }
- public int compareTo(Object g)
- {
- return ((Student) g).age-age;
- }
- }
- public Registration()
- {
- ogline= new PriorityQueue<Student>();
- reline=new LinkedList<Student>();
- }
- public void enterLine()
- {
- Scanner f=new Scanner(System.in);
- String n;
- int g;
- out.print("Enter the student's name ==> ");
- n=f.nextLine();
- out.print("Enter the student's grade ==> ");
- g=f.nextInt();
- Student student=new Student(n,g);
- ogline.add(student);
- }
- public void displayOriginalLine()
- {
- PriorityQueue<Student> ogline2=new PriorityQueue<Student>();
- while(!ogline.isEmpty())
- {
- ogline2.add(ogline.peek());
- out.print(ogline.remove());
- }
- while(!ogline2.isEmpty())
- {
- ogline.add(ogline2.remove());
- }
- out.println();
- out.println();
- out.println();
- }
- public void disperseLine()
- {
- while(!ogline.isEmpty())
- {
- reline.add(ogline.remove());
- }
- }
- public void exitLine()
- {
- while(!reline.isEmpty())
- {
- out.print(reline.remove());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement