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!
- 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).
- compareAge should return the number of years difference in age between the two people
- zero should be returned if the people are the same age
- a positive integer should be returned if this person is older than otherPerson
- 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 anotherStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started