Write code for PersonManagement class. This class contains the array of Person class (code is given below) and also following methods: set: This method receives the array of person class and set the attribute. displayAll: This method will display values of all persons. sort: This method will sort the array according to age values of the persons with ascending order using Selection Sort. reverse: This method will reverse the order of the array. getPersons: This method will return the array of the persons (attribute). displayEvenAgePerson: This method will display all those persons values who have even age. displayOddAgePerson: This method will display all those persons values who have odd age. displayPrimeAgePerson: This method will display only those persons values who have prime number age. Following is the class of Person: public class Person {        private String Name;        public int age;               public void set(String Name, int age)        {               this.Name = Name;               if(age > 0 && age <= 100)                      this.age = age;               else                      this.age = 1;        }               public void display()        {               System.out.println("Name: " + this.Name +" ,Age: " + this.age);        }               public static void main(String[] args)        {               PersonManagement personManagement = new PersonManagement();               Person p1 = new Person(), p2 = new Person(), p3 = new Person(), p4 = new Person(), p5 = new Person();               p1.set("Asad", 103);               p2.set("Ali", 17);               p3.set("Usman", 16);               p4.set("Raees", 18);               p5.set("Mujeeb", 15);               Person[] persons = new Person[]{p1,p2,p3,p4,p5};               System.out.println("Persons in Array");               personManagement.set(persons);               personManagement.displayAll();               System.out.println("Persons after Selection Sort");               personManagement.sort();               personManagement.displayAll();               System.out.println("Persons after Reverse of Array");               personManagement.reverse();               personManagement.displayAll();               System.out.println("Persons with Even Ages");               personManagement.displayEvenAgePerson();               System.out.println("Persons with Odd Ages");               personManagement.displayOddAgePerson();               System.out.println("Persons with Prime Ages");               personManagement.displayPrimeAgePerson();        } } Output of the Main method is: Persons in Array Name: Asad ,Age: 1 Name: Ali ,Age: 17 Name: Usman ,Age: 16 Name: Raees ,Age: 18 Name: Mujeeb ,Age: 15 Persons after Selection Sort Name: Asad ,Age: 1 Name: Mujeeb ,Age: 15 Name: Usman ,Age: 16 Name: Ali ,Age: 17 Name: Raees ,Age: 18 Persons after Reverse of Array Name: Raees ,Age: 18 Name: Ali ,Age: 17 Name: Usman ,Age: 16 Name: Mujeeb ,Age: 15 Name: Asad ,Age: 1 Persons with Even Ages Name: Raees ,Age: 18 Name: Usman ,Age: 16 Persons with Odd Ages Name: Ali ,Age: 17 Name: Mujeeb ,Age: 15 Name: Asad ,Age: 1 Persons with Prime Ages Name: Ali ,Age: 17

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write code for PersonManagement class. This class contains the array of Person class (code is given below) and also following methods:

  • set: This method receives the array of person class and set the attribute.
  • displayAll: This method will display values of all persons.
  • sort: This method will sort the array according to age values of the persons with ascending order using Selection Sort.
  • reverse: This method will reverse the order of the array.
  • getPersons: This method will return the array of the persons (attribute).
  • displayEvenAgePerson: This method will display all those persons values who have even age.
  • displayOddAgePerson: This method will display all those persons values who have odd age.
  • displayPrimeAgePerson: This method will display only those persons values who have prime number age.

Following is the class of Person:

public class Person {

       private String Name;

       public int age;

      

       public void set(String Name, int age)

       {

              this.Name = Name;

              if(age > 0 && age <= 100)

                     this.age = age;

              else

                     this.age = 1;

       }

      

       public void display()

       {

              System.out.println("Name: " + this.Name +" ,Age: " + this.age);

       }

      

       public static void main(String[] args)

       {

              PersonManagement personManagement = new PersonManagement();

              Person p1 = new Person(), p2 = new Person(), p3 = new Person(), p4 = new Person(), p5 = new Person();

              p1.set("Asad", 103);

              p2.set("Ali", 17);

              p3.set("Usman", 16);

              p4.set("Raees", 18);

              p5.set("Mujeeb", 15);

              Person[] persons = new Person[]{p1,p2,p3,p4,p5};

              System.out.println("Persons in Array");

              personManagement.set(persons);

              personManagement.displayAll();

              System.out.println("Persons after Selection Sort");

              personManagement.sort();

              personManagement.displayAll();

              System.out.println("Persons after Reverse of Array");

              personManagement.reverse();

              personManagement.displayAll();

              System.out.println("Persons with Even Ages");

              personManagement.displayEvenAgePerson();

              System.out.println("Persons with Odd Ages");

              personManagement.displayOddAgePerson();

              System.out.println("Persons with Prime Ages");

              personManagement.displayPrimeAgePerson();

       }

}

Output of the Main method is:

Persons in Array

Name: Asad ,Age: 1

Name: Ali ,Age: 17

Name: Usman ,Age: 16

Name: Raees ,Age: 18

Name: Mujeeb ,Age: 15

Persons after Selection Sort

Name: Asad ,Age: 1

Name: Mujeeb ,Age: 15

Name: Usman ,Age: 16

Name: Ali ,Age: 17

Name: Raees ,Age: 18

Persons after Reverse of Array

Name: Raees ,Age: 18

Name: Ali ,Age: 17

Name: Usman ,Age: 16

Name: Mujeeb ,Age: 15

Name: Asad ,Age: 1

Persons with Even Ages

Name: Raees ,Age: 18

Name: Usman ,Age: 16

Persons with Odd Ages

Name: Ali ,Age: 17

Name: Mujeeb ,Age: 15

Name: Asad ,Age: 1

Persons with Prime Ages

Name: Ali ,Age: 17

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Program on Numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education