Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that creates a Person class that contains strings that represent

ID: 3727281 • Letter: W

Question

Write a program that creates a Person class that contains strings that represent the first and last name of a person and their age. You will need to create a Queue class that will store each person in the queue. The Queue class implements the quicksort algorithm on objects in the queue based on last name or age.

The objects once sorted via the quicksort algorithm need to be printed out in descending order by last name and descending order by age.

This needs to be in JAVA.

There needs to be a test program that tests the queue class

Explanation / Answer

import java.util.*;

class Person
{
private String firstName,lastName;
private int age;

public Person(String firstName,String lastName,int age)//argument constructor
{
  this.firstName = firstName;
  this.lastName = lastName;
  this.age = age;
}
public String toString()
{
  return " "+firstName + " "+ lastName +" "+age;
}
}
class PersonQueue
{
public static void main (String[] args)
{

//queue of objects  
Queue<Person> q = new LinkedList<>();
System.out.println(" Queue: " + q);
//add objects to queue
q.add(new Person("John","Smith",47));
q.add(new Person("Mark","Johnson",34));
q.add(new Person("Candy","Jones",28));
//remove front object of queue
//Person i3 = (Person) q.remove();

//display elements of queue
Object[] vals1 = q.toArray();
for (Object obj : vals1) {
System.out.println(obj);
}
}
}

output:

Queue: []

John Smith 47

Mark Johnson 34

Candy Jones 28

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote