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

In Java Create an array of Student objects. Display the students by lastName in

ID: 3928314 • Letter: I

Question

In Java Create an array of Student objects.
Display the students by lastName in UNSORTED
order. Apply the Quick3way sort and Display the
students by lastName in SORTED order.

public class TestQuick3wayStudent {
public static void main (String [ ] args ) {
/*
***Create your array of Student objects with AT LEAST 5 names
*/

System.out.println ( " ____________________________");
  
/*
***LOOP through your array and print out each UNSORTED check by student lastname
*/

System.out.println ( " ____________________________");

Quick3way.sort (students);

/*
***LOOP through your array and print out each SORTED check by student lastname
*/

System.out.println ( " ____________________________");
}
}

-Have to create a class Student. The properties/instance variables will be as
follows:

Integer age;
String state;
String firstName;
String lastName;

Explanation / Answer

Hi, Please find my implementation.

I have implemeted Student class such a way that it sort based on lastName.

Since you have not posted Quick3way.java, so i can not test program.

Please let me know in case of any issue.

############## Student.java #############

public class Student implements Comparable<Student> {

  

// instance variable

   private Integer age;

   private String state;

   private String firstName;

   private String lastName;

  

// constructor

   public Student(Integer age, String state, String firstName, String lastName) {

       this.age = age;

       this.state = state;

       this.firstName = firstName;

       this.lastName = lastName;

   }

// comparing based on lastName

@Override

   public int compareTo(Student o) {

       return lastName.compareTo(o.lastName);

   }

// setters and getters

  

   public Integer getAge() {

       return age;

   }

   public void setAge(Integer age) {

       this.age = age;

   }

   public String getState() {

       return state;

   }

   public void setState(String state) {

       this.state = state;

   }

   public String getFirstName() {

       return firstName;

   }

   public void setFirstName(String firstName) {

       this.firstName = firstName;

   }

   public String getLastName() {

       return lastName;

   }

   public void setLastName(String lastName) {

       this.lastName = lastName;

   }

  

}

############ TestQuick3wayStudent.java ##########################

public class TestQuick3wayStudent {

   public static void main (String [ ] args ) {

       /*

       ***Create your array of Student objects with AT LEAST 5 names

       */

       // creating Student array

       Student []students = {

               new Student(24, "UK", "Alex", "Gender"),

               new Student(22, "USA", "Pravesh", "Kumar"),

               new Student(20, "BLR", "Mukesh", "Mittal"),

               new Student(23, "IND", "Tinu", "Dabi"),

               new Student(25, "Germani", "Vishal", "Gaana")

       };

       System.out.println ( " ____________________________");

       /*

       ***LOOP through your array and print out each UNSORTED check by student age

       */

       for(int i=0; i<students.length; i++){

           System.out.println(students[i].getLastName());

       }

       System.out.println ( " ____________________________");

       Quick3way.sort(students);

       /*

       ***LOOP through your array and print out each SORTED check by student age

       */

       for(int i=0; i<students.length; i++){

           System.out.println(students[i].getLastName());

       }

       System.out.println ( " ____________________________");

   }

}

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