logo Practice-It logo

xmasMoney

Language/Type: Java Guava Table collections
Author: Marty Stepp (on 2013/01/22)

Write a method named xmasMoney that computes the difference between the total cost of gifts a person received, and the total money the person spent on their Xmas gifts to others. The method accepts two parameters: the person's name of interest (as a string), and a Table of Xmas gift prices, where the two string keys (person1, person2) map to a real number (double) representing the price of the gift that person1 gave to person2 for Xmas. It is possible that not every person gave a gift to every other person. If the person did not give or receive any gifts, return 0.0. For example, if the name is Mary and the table is the following:

{John={Mary=50.50, Zora=10.25},
 Mary={John=24.50, Zora=10.50},
 Stan={Mary=45.00},
 Zora={John=85.75, Stan=40.00, Zora=99.25}}

Then you would return 60.5 because Mary received $95.50 worth of presents from John and Stan but spent only $35.00 total on her presents to John and Zora.

Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.