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

Interacting Objects Complete the provided Person class. A person object has a na

ID: 3914497 • Letter: I

Question

Interacting Objects Complete the provided Person class. A person object has a name and some money. Write the body of the compare method. This method how much money they have. When you call allows us to compare two person objects based on personi.compare(person2) the method will return a negative number of person1 has less money than person2 (it does not matter what negative int you return), return zero it person1 and person2 have the same amount of money, or return a positive number if persont has more money then person2 Complete the shareMoney method that shares the money of a given person object with another. For the shareMoney method, be sure that each person has their own money That is, even though they have the same money value they should each have their own money object they they are referencing O Type here to search ENG 652 US 2018-0

Explanation / Answer

public class Money { private double amount; public Money(double amount) { this.amount = amount; } public Money() { amount = 0; } public double getAmount() { return amount; } public void setAmount(double amount) { this.amount = amount; } } public class Person { private String name; private Money money; public Person(String name, Money money) { this.name = name; this.money = money; } public Person(String name) { this(name, new Money()); } public int compare(Person person) { return Double.compare(money.getAmount(), person.money.getAmount()); } public void shareMoney(Person other) { money = other.money; } }

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