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
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
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


Trending now
This is a popular solution!
Step by step
Solved in 2 steps









