Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Give the complete definition of class called person that has two instance variab

ID: 3655615 • Letter: G

Question

Give the complete definition of class called person that has two instance variables, one for the person's name and the other for the person's age.Include accessor methods and mutator methodes for each instance variable. Also, include a method that sets both the name and age of person.Add methode to the person class to perform the following tasks: * Set the name attribute of a person object. *Set the age attribute of a person object. *Test whether two person objects are equal( have the same name and age). *Test whether two person objects have the same name. *Test whether two person objects are the same age. *Test whether one person object is order than another. *Test whether one person object is younger than another.

Explanation / Answer

//Accessor for firstName public String getFirstName() { return firstName; } //Accessor for middleNames public String getMiddlesNames() { return middleNames; } //Accessor for lastName public String getLastName() { return lastName; } These methods always return the same data type as their corresponding private field (e.g., String) and then simply return the value of that private field. We can now access their values through the methods of a Person object: public class PersonExample { public static void main(String[] args) { Person dave = new Person("Dave", "Bob Bill", "Davidson", "12 Pall Mall"); System.out.println(dave.getFirstName() + " " + dave.getMiddlesNames() + " " + dave.getLastName()); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote