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
Step by stepSolved in 2 steps with 1 images
- JAVA PROGRAM Chapter 7. PC #16. 2D Array Operations Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: • getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. • getAverage. This method should accept a two-dimensional array as its argument and return the average of all the values in the array. • getRowTotal. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the total of the values in the specified row. • getColumnTotal. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The method should return the…arrow_forwardJAVA ARRAY MANIPULATION QUESTION: make a method called manipulator that takes a double array as parameter and modifies it. The method will modify the array then print the array. The method must modify the existing array, it CAN NOT create a different array as the solution. The manipulator method will be a void method. Remember: To get an average of 2 digits you add them together then divide by 2. Average of x and y = (x+y)/2 Modifications the method will do: For every 2 consecutive elements in the array, both the elements are replaced by their average. If the number of elements in an array is odd don't modify the last number of the array. Basically, you find the average of 2 consecutive elements then replace both of the elements with that value. Examples: Array = {2.0,3.0} will be changed to {2.5,2.5} when passed to the manipulator method Array = {2.0,3.0,45} will be changed to {2.5,2.5,45} when passed to the manipulator method Array = {2.0,3.0,45,55} will be changed to…arrow_forwardWhen an array is passed as a parameter to a method, modifying the elements of the array from inside the function will result in a change to those array elements as seen after the method call is complete. O True O Falsearrow_forward
- Sum values - Method, property, both (please answer which one) can you sum values of a numpy array via a method function or through its attributes only or botharrow_forward17. Phone Book ArrayList Write a class named PhoneBookEntry that has fields for a person's name and phone number. The class should have a constructor and appropriate accessor and mutator methods. Then write a program that creates at least five PhoneBookEntry objects and stores them in an ArrayList. Use a loop to display the contents of each object in the ArrayList.arrow_forward1. Square Roots Create a class with a method that, given an integer, returns an array of double-precision floating point numbers (known in Java as double), each of which is a square root of a number between 2 and the parameter to the method. For example, if the parameter is 5, the method should return an array of 4 doubles, with approximate values 1.4142135623, 1.7320508075, 2.0, and 2.2360679774. Your method should check the validity of the parameter, and take appropriate action if the parameter is invalid. 2. Reading Files Create a class with a method that, given a string representing a file name, returns an integer with the number of characters in the file. For example, if the file has 10 characters, your method must return the number 10. 3. Main Class Create a class HW1.java with a main method that does both of the following: calls the method from part 1 with a random integer between 0 and 10, and prints each of the numbers in the result. The numbers should all be printed on the…arrow_forward
- 11:02 all 10% + Create 1 1000.01 Create 2 2000.02 Create 3 3000.03 Deposit 111.11 Deposit 2 22.22 Withdraw 4 5000.00 Create 4 4000.04 Withdraw 1 0.10 Balance 2 Withdraw 2 0.20 Deposit 3 33.33 Withdraw 4 0.40 Bad Command 65 Balance 1 Balance 2 Balance 3 Balance 4arrow_forwardclass Main { // this function will return the number elements in the given range public static int getCountInRange(int[] array, int lower, int upper) { int count = 0; // to count the numbers // this loop will count the numbers in the range for (int i = 0; i < array.length; i++) { // if element is in the range if (array[i] >= lower && array[i] <= upper) count++; } return count; } public static void main(String[] args) { // array int array[] = {1,2,3,4,5,6,7,8,9,0}; // ower and upper range int lower = 1, upper = 9; // throwing an exception…arrow_forward10 Build the Sudoku Reviewer ( the testing program). The specification is below. Please note: you DO NOT have to build a Sudoku solver. To test you just need to build a class that generates a 9x9 2D array with the values you want to test. You can assume the value types are valid. (integers from 1-9). 1-The main purpose is to make sure the Sudoku solver actually solved it correctly! 2- You are also confirming the solver solves puzzle in no longer than a minute 3- Solver (not the reviewer) requires 7 INDICES (ELEMENTS) filled in the input array at least. 4- The reviewer receives both the original puzzle and the solution. The Reviewer needs to confirm the solution is not only a valid SudoKu solution but also the solution to the original puzzle. 5- Solver will return a 2d array filled with -1s if input array has an error/bad input (exception). Reviewer will check for this case.arrow_forward
- in C#, Visual Basic Write an app for Boston Airlines that allows a customer to reserve a seat on the airline’s only plane (capacity: 10 seats). Radio buttons should allow the choice between First Class and Economy. The app should then assign a seat in the first-class section (seats 1–5) or the economy section (seats 6–10). Use a one-dimensional array of type bool to represent the seating chart of the plane. Initialize all the elements of the array to false to indicate that all the seats are empty. As each seat is assigned, set the corresponding element of the array to true to indicate that the seat is no longer available. Your app should never assign a seat that has already been assigned. When the economy section is full, your app should ask the person if it is acceptable to be placed in the first-class section (and vice versa). If yes, make the appropriate seat assignment. If no, display the message “Next flight leaves in 3 hours."arrow_forwardJava Programarrow_forwardJavaarrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY