Student Name Captain Jack Problem & Design Worksheet

PROGRAM PROBLEM
The pirate Captain Jack arrives in Tortuga after plundering the high seas. Captain Jack doesn't want to divvy up the treasure yet, so he gives each of the crew (except for himself and the first mate) 3 pieces of gold and sends them to town (crewMembers * 3 = townGold). Then, he counts the loot (1000) and decides how to split it up. Captain Jack takes 12% of the total gold that came into port (1000, 12%, 120). Then the first mate takes 8% of the remaining gold (1000 -120 = 880 * .08). The next morning, the gold that is left (totalGold – jackInitial – smeeInitial – townGold) is divided evenly among the all members of the crew, including Captain Jack and the First Mate. If the remaining treasure can't be split evenly, the bits that are left over (modulus division %) are given to the Pirate's Benevolent Association. No one gets a fraction of a gold coin!
The problem is to compute how much gold each person gets, and if any, how much goes to the
Pirate's Benevolent Association.
Your program should:
·  Ask the User how much gold the pirate ship came into port with.
·  Ask the User how many pirates are on the ship, including Captain Jack and the first mate.
·  Then calculate and print how much gold the captain, first mate, each of the crew, and the Pirate's Benevolent fund gets.
What is the problem to be solved?
How much Gold went to town? (townGold) How many crew members (pirateCrew)? 12 * 3 = 36 (townGold)
TOTAL LOOT = 1000?
Jack’s Total Take? 12% of the totalGold
Mr. Smee’s Total Take? 8% of the remainingGold
Each Crew Member’s Total Take * CREW MEMBERS?
How many pieces remain to go to the Pirate’s Bene Fund?
Add the above to equal what the total gold is.
What does the User have to input?
totalGold and crewMembers (excluding Jack & Smee)
captainandSmee = 2;
What will my program produce? Take in the gold, divvy it up, add it back, it should equal the amount you took in.
/ What do I know? ONLY USING INTEGERS (int)
Integer Division / (whole number)
Modulus Division % (gives the remainder)
SAMPLE: 10 / 3 = 3 R 1
3 = 10 / 3; // returns the whole number
1 = 10 % 3; // returns the remainder – Pirate’s Bene Fund
CASTING to an INT
#1 townGold = crewMembers * 3;
#2 jackInitialTake = (int) (totalGold * .12);
#3 smeeInitialTake = (int) (totalGold – jackInitialTake) * .08);
#4 leftOverGold = (totalGold – townGold – jackInitialTake – smeeInitialTake)
Pseudo-code (write it out in English)
Step 1: Define Variables
int totalGold, jackInitialTake, smeeInitialTake, crewMembers,
Int townGold, leftOverGold, crewMemberGold, pirateFund;
Step 2: Ask for Input
totalGold
crewMembers (excluding Jack & First Mate)
Step 3: Compute
// use integer & modulus division to get the answers
3 = 10 / 3; // returns the whole number
1 = 10 % 3; // returns the remainder
#1 Compute townGold = crewmember * 3;
#2 Jack’s Initial Total Take (12% of the total)? jackInitialTake = (int) (totalGold * .12)
#3 Mr. Smee’s Initial Total Take (totalGold – jackInitial) = remaining = 8% = .08?
#4 goldLeftOver = totalGold –jackInitial – smeeInitial – townGold;
#5 divideEven = goldLeftOver / (crewMembers + 2); 3 = 10 / 3; // returns the whole number
#6 pirateFund = goldLeftOver % (crewMembers + 2); 1 = 10 % 3; // returns the remainder
#7 add all back together, to get the initial totalGold
Step 4: Output
Show the totalGold coming in, divvied out, then add back up to equal the totalGold.
// 4 quarters, 3 children, each receive 1 quarter, with 1 quarter leftover