Forty Thieves

Goals

Note

Overview

The Forty Thieves are a criminal organization whose members are supposed to contribute all their takings to a communal pot that's shared amongst all the Thieves. The problem is, thieves are greedy and generally underreport their take after each job. All the thieves have a "greed" rating, which represents the percentage of the money they will keep for themselves and add to their personal stash -- the rest will go to the communal pot (shared stash). When a thief gets captured, the thief loses his or her personal stash. If there is enough money in the communal pot to cover their bail, the Forty Thieves spend that amount to bail the thief out (otherwise the thief remains captured).

Write the Thief class to simulate the behavior of a Thief in Thief.java. Add any necessary variables and complete the isFree(), getStash(), getSharedStash(), rob(), and getCapturedAndAttemptBail() methods. Assume that greed is between 0 and 1 (inclusive), and that all values passed to rob() and getCapturedAndAttemptBail() are greater than 0.

Overview of Methods

Return-Type Method Name Input(s) type Behavior
boolean isFree none returns true if the Thief is free, false otherwise
double getStash none returns the size of the Thief's personal stash
double getSharedStash none returns the size of the Thieves' communal stash
void rob double the thief siezes the given amount of money, contributing the appropriate amount to the communal stash and keeping the rest for itself. Assumes the thief is free.
boolean getCapturedAndAttemptBail double the thief is captured as per the description above. Try to bail out the Thief, and return true if successful (false otherwise). Assumes the Thief is free. "Bail" means money paid to court to release a criminal.
double getThievesStash none returns the size of the communal stash (Note: there little bit of difference between this method and getSharedStash)

Sample Interactions thief.hist (use .hist file to save time typing).

> Thief bill = new Thief(.25);  // bill's greed factor is .25, meaning he keeps 25% for himself
> Thief george = new Thief(.5); // george keeps 50% of the amount he robs to himself
> bill.getStash()
0.0
> bill.getSharedStash()
0.0
> bill.rob(800.00);  // bill robs $800 and keeps 25%  for himself
> bill.getStash()
200.0
> bill.getSharedStash()
600.0
> bill.isFree()
true
> george.rob(1000.00);  // george robs $1000 and keeps 50% for himself
> george.getStash()
500.0
> george.getSharedStash()
1100.0
> bill.getSharedStash()
1100.0
> bill.getCapturedAndAttemptBail(400.00) 
true           // there's enough shared $ to cover bill's $400.00 bail
> bill.isFree()
true
> bill.getStash()
0.0
> bill.getSharedStash()
700.0
> george.getStash()
500.0 > george.getCapturedAndAttemptBail(750.00) false // there's not enough shared $ to cover george's $750.00 bail > george.isFree() false > george.getStash() 0.0 > george.getSharedStash() //line 1 700.0 > bill.getSharedStash()
700.0
> Thief.getThievesStash() //What is the difference between this statement and line 1 700.00