Due Date: Sunday, September 13, 2009.
Objective: The goal of this assignment is to practice using 2-dimensional
arrays.
Background: To study human behavior, researchers use simple economic games
like the following Trust Game played between two players: an Investor and a
Trustee. In the experiment, several pairs play, and each game between two players
continues for several rounds. In every round:
- First, an investor is given $20.
- The investor can invest any integer part of this amount, 0, $1, $2, ...,
$20 with the trustee.
- The experimenters triple this amount and give the triple amount to the
trustee.
- The trustee is free to return any part of this triple amount to the investor
and keep the rest.
For example, if the investor invested $15, then the trustee gets $45 and returns
$22 to the investor. The trustee has an incentive to return some money to the
investor -- otherwise, the investor will not invest anything in the next round,
and the trustee will have no profit. This game is used because it captures a lot
of notions about trust.
Assignment: Write a program that, first, stores the game results (which
are originally given in a file, one game per line) in two two-dimensional arrays:
- the investor array records how much money each player invested in each round;
- the trustee array records how much money each trustee returned in each round.
Your program should include the following methods:
- a method that fills in the arrays from the given file;
- a method that, given an investor number, returns the average amount invested
by this investor in all the rounds;
- a method that, given a trustee number, returns the average amount returned
by the trustees in all the rounds;
- a method that returns the average amount invested by all investors in all
the rounds;
- a method that returns the average amount returned by all trustees in all
the rounds;
- a method that, given a round, returns the average amount invested in this
round;
- a method that, given a round, returns the average amount returned in this
round;
- a method that, given a round, returns the index of the investor who invested
the largest amount of money in this round.
As an example, let us assume that we have two pairs playing the game, with each
game consisting of two rounds. In the first game:
- in the 0th round, the investor invested $10, and the trustee returned $15;
- in the 1st round, the investor invested $14, and the trustee returned $11.
In the second game:
- in the 0th round, the investor invested $5, and the trustee returned $12;
- in the 1st round, the investor invested $20, and the trustee returned $7.
The corresponding file has the form
10 15 14 11
5 12 20 7
The investor array has the form
10 14
5 20
and the trustees array has the form
15 11
12 7
In this case:
- the average amount invested by the 0th investor is (10 + 14) / 2=
$12.00, and
- the average amount invested by the 1st investor is (5 + 20) / 2=
$12.50.
For extra credit: Redo Programming Assignment 1 using a two-dimensional
array instead of two one-dimensional arrays.