Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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!

image text in transcribed

  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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

Finding and scheduling appointments with new prospective clients.

Answered: 1 week ago