JAVA OOP Questions (Getter Setter Functions)
JAVA OOP Questions (Getter Setter Functions)
Task 1:
You are required to implement a `Person` class in Java, which represents a human being. The class should
have the following attributes:
- `name` (String): Represents the name of the person.
- `birthYear` (int): Represents the year of birth of the person.
- `deathYear` (int): Represents the year of death of the person. If the person is still alive, the value should
be set to -1.
The Person class should provide the following functionalities:
1. Parameterized Constructor: A constructor that initializes the `name`, `birthYear`, and
`deathYear` attributes of the person.
2. Copy Constructor: A constructor that creates a copy of an existing `Person` object.
3. Accessor Methods: Getter methods to access the `name`, `birthYear`, and `deathYear` attributes of
the person.
4. Print Method: A method that displays the information of the person, including their name, birth
year, and death year.
In the `main` function, you need to test the functionality of the `Person` class by performing the following
actions:
1. Create a `Person` object `p1` with the following details: name - " Abdul Sattar Edhi", birthYear -
1928, deathYear - 2016.
2. Create a `Person` object `p2` using the copy constructor, with `p1` as the source object.
3. Create a `Person` object `p3` using the parametrized constuctor
4. Call the `print` method on `p1`, `p2`, and `p3` to display their respective information.
5. Create a `Person` object `p4` with no death information and print it.
Sample Output:
Name: Abdul Sattar Edhi Name: Abdul Sattar Edhi
Birth Year: 1928 Birth Year: 1928
Death Year: 2016 Death Year: 2016
Sample Output:
Player Name: Babar Azam
Total Score: 78
Balls Played: 54
Number of Fours: 8
Number of Sixes: 3
Strike Rate: 144.44
Boundary Percentage: 25.92