Question: I need help with finalizing a java problem. The main piece is the last 3 bullets for testing with the parameters from below. I'm having

I need help with finalizing a java problem. The main piece is the last 3 bullets for testing with the parameters from below. I'm having a hard time figuring out how to return the number of years difference in age between the two people that are already set. The code works, it just doesn't meet the criteria for returning the positive and negative integer. If anything else is needed, let me know!

I need help with finalizing a java problem. The main piece is

  1. The last three tests have to deal with comparing a persons age. Perform all three age comparison tests in one method called compareAge(Person otherPerson).
    1. compareAge should return the number of years difference in age between the two people
    2. zero should be returned if the people are the same age
    3. a positive integer should be returned if this person is older than otherPerson
    4. a negative integer should be returned if this person is younger than otherPerson

Right now, this is the code from "Person" class I've been trying to transform for the "PersonDemo" class, but I can't figure out how to transform the code :

Person.java class code:

public int compareAge(Person otherPerson) { if(age == otherPerson.age) { return 0; } else if(age

PersonDemo.java class code for testing:

if(bob.compareAge(jason) == 1) { System.out.println("Bob is younger than Jason"); } else if(bob.compareAge(jason) == -1) { System.out.println("Bob is older than Jason"); } else { System.out.println("0. Bob is the same age as Jason"); }

2. Add methods to the Person class from Self-Test Question 16 to perform the following tasks: Set the name attribute of a Person object. Set the age atribute 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 older than another. Test whether one Person object is younger than another

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!