Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Student implements Comparable{
- private String fullName;
- private Date registrationDate;
- public Person(String fullName){
- this.fullName = fullName;
- }
- public String getFullName() {
- return fullName;
- }
- public void setFullName(String fullName) {
- this.fullName = fullName;
- }
- public Date getRegistrationDate() {
- return registrationDate;
- }
- public void setRegistrationDate(Date registrationDate) {
- this.registrationDate = registrationDate;
- }
- @Override
- public int compareTo(Object obj) {
- Person person = (Person) obj;
- if(person instanceof Staff){
- return 1;
- }else if(person instanceof Student){
- return -1;
- }
- else if(getRegistrationDate().before(person.getRegistrationDate())){
- return 1;
- }else if(getRegistrationDate().after(person.getRegistrationDate())){
- return -1;
- }
- return 0;
- }
- }
- public class Staff extends Person{
- public Staff(String fullName){
- this.fullName = fullName;
- }
- }
- public class Student extends Member{
- public Student(String fullName){
- this.fullName = fullName;
- }
- }
- public class School {
- public static void main(String args[]) {
- //list of students
- Student student1 = new Student("John Kent");
- Date dateStudent1Joined = new GregorianCalendar(2014, Calendar.JULY, 1).getTime();
- student1.setRegistrationDate(dateStudent1Joined);
- Student student2 = new Student("Peter Tush");
- Date dateStudent2Joined = new GregorianCalendar(2014, Calendar.JULY, 2).getTime();
- student2.setRegistrationDate(dateStudent2Joined);
- Student student3 = new Student("Mike Monroe");
- Date dateStudent3Joined = new GregorianCalendar(2014, Calendar.JULY, 3).getTime();
- student3.setRegistrationDate(dateStudent3Joined);
- Student student4 = new Student("Tom Johnson");
- Date dateStudent4Joined = new GregorianCalendar(2014, Calendar.JULY, 4).getTime();
- student4.setRegistrationDate(dateStudent4Joined);
- Student student5 = new Student("Tony Spencer");
- Date dateStudent5Joined = new GregorianCalendar(2014, Calendar.JULY, 5).getTime();
- student5.setRegistrationDate(dateStudent5Joined);
- //list of staff
- Staff staff1 = new Staff("Luke Clint");
- Date dateStaff1Joined = new GregorianCalendar(2014, Calendar.JULY, 6).getTime();
- staff1.setRegistrationDate(dateStaff1Joined);
- Staff staff2 = new Staff("Ron West");
- Date dateStaff2Joined = new GregorianCalendar(2014, Calendar.JULY, 7).getTime();
- staff2.setRegistrationDate(dateStaff2Joined);
- Staff staff3 = new Staff("Jim Gary");
- Date dateStaff3Joined = new GregorianCalendar(2014, Calendar.JULY, 8).getTime();
- staff3.setRegistrationDate(dateStaff3Joined);
- //create a queue data structure to hold Persons in school
- PriorityQueue<Person> schoolQueue = new PriorityQueue<Person>();
- //add students to queue
- schoolQueue.offer(student1);
- schoolQueue.offer(student2);
- schoolQueue.offer(student3);
- schoolQueue.offer(student4);
- schoolQueue.offer(student5);
- //add staff to queue
- schoolQueue.offer(staff1);
- schoolQueue.offer(staff2);
- schoolQueue.offer(staff3);
- //print names of people in queue
- for(Member member : clubQueue){
- String memberName = member.getFullName();
- System.out.println(memberName);
- }
- }
- }
- @Override
- public int compareTo(Object obj) {
- Person person = (Person) obj;
- if(person instanceof Staff){
- return 1;
- }else if(person instanceof Student){
- return -1;
- }
- else if(getRegistrationDate().before(person.getRegistrationDate())){
- return 1;
- }else if(getRegistrationDate().after(person.getRegistrationDate())){
- return -1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement