Question

In Java Create an array of Student objects. Display the students by age in UNSORTED order....

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

public class TestQuickStudent {
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 age
*/

System.out.println ( " ____________________________");

Quick.sort (students);

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

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;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi, Please find my implementation.

Since you have not posted Quick.java, so i have not tested program.

######## 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 age

@Override

   public int compareTo(Student o) {

       return age.compareTo(o.age);

   }

// 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;

   }

  

}

##################   TestQuickStudent.java #############

public class TestQuickStudent {

   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].getAge());

       }

       System.out.println ( " ____________________________");

       Quick.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].getAge());

       }

       System.out.println ( " ____________________________");

   }

}

Add a comment
Know the answer?
Add Answer to:
In Java Create an array of Student objects. Display the students by age in UNSORTED order....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java: Executable Class create an array of Employee objects. You can copy the array you...

    In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...

  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

  • JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate...

    JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate passing array reference to a method;        III. Demonstrate creating array of objects that prints out only x 0.0 for all objects. PROJECT 5C - ARRAYS Create a new file called " EventArray5C". There are some "challenging" directions in this project. . 1.Prepare a document box (tell me that task(s) the application is to accomplish, how it will accomplish the tasks, the author of...

  • ( Object array + input) Write a Java program to meet the following requirements: 1. Define...

    ( Object array + input) Write a Java program to meet the following requirements: 1. Define a class called Student which contains: 1.1 data fields: a. An integer data field contains student id b. Two String data fields named firstname and lastname c. A String data field contains student’s email address 1.2 methods: a. A no-arg constructor that will create a default student object. b. A constructor that creates a student with the specified student id, firstname, lastname and email_address...

  • Here is the code from the previous three steps: #include <iostream> using namespace std; class Student...

    Here is the code from the previous three steps: #include <iostream> using namespace std; class Student { private: //class variables int ID; string firstName,lastName; public: Student(int ID,string firstName,string lastName) //constructor { this->ID=ID; this->firstName=firstName; this->lastName=lastName; } int getID() //getter method { return ID; } virtual string getType() = 0; //pure virtual function virtual void printInfo() //virtual function to print basic details of a student { cout << "Student type: " << getType() << endl; cout << "Student ID: " << ID...

  • Using Java: Create an array with the size of 10 and assign student details (Name, ID,...

    Using Java: Create an array with the size of 10 and assign student details (Name, ID, age and TotalMarks) to the array. Perform the Heap Sort to sort the students in ascending order based on their total marks. Steps: • Create the student list (use Random class in java to generate the age (15- 25) and total (0-100)) • Print the Student List in a table format • Perform Heap sort based on the total marks of the students •...

  • Write java class “BinarySearch” that uses recursion to find the index of a target value in...

    Write java class “BinarySearch” that uses recursion to find the index of a target value in an ascending sorted array. If not found, the result is -1. The array has to be unsorted before you sort it. Use “ BinarySearchDriver.java” to drive the “BinarySearch” class /************************************************************* * BinarySearchDriver.java * Student Name * *. *************************************************************/ public class BinarySearchDriver { public static void main(String[] args) {     int[] array = new int[] {55, 88, 33, 5, 8, 12, 16, 23, 45}; /unsorted...

  • Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person...

    Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person and Student represent individuals with a first and last name as String class variables, and Student has an additional int class variable that represents a ID number. The Roster class represents a group of people that are objects of either the Person or Student class. It contains an ArrayList. The Person class has been completed for you with class variables, a constructor, and a...

  • A teacher wants to create a list of students in her class. Using the existing Student...

    A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...

  • C# visual studio 2019 For this  you will create two student objects and then print out the...

    C# visual studio 2019 For this  you will create two student objects and then print out the objects values. Within the Student Class you will have the following properties: StudentID LastName FirstName Major Within the Main you will create 2 student objects by setting each of their property values. You will then write out a header line and each of the student objects to the console.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT