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:

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

solve eith java:-

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 with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY