[CSC 204] Six Loops to Rule them All
Andrew J. Pounds
pounds_aj at mercer.edu
Wed Nov 2 17:04:05 EDT 2016
In the past 48 hours I have talked to several of you that are having
great trouble figuring out how to have the loops keep running while you
are rolling for certain numbers. Here is an example from some of my
old code for how you might do this...
| String roll;||
|| String pokerHand;||
|| int totalScore = 0;||
|| int bonus;|
| boolean doneWithOnes = false;|
| System.out.println(" *** ROLLING FOR ONES ***");||
|| while (!doneWithOnes) {||
|| int handScore = 0;||
|| roll = Dice.roll();||
|| doneWithOnes = !foundInRoll(roll,1);||// See if there is
one in the roll
|| if (!doneWithOnes) {||
|| System.out.print( roll + " " );||
|| handScore = countNumberInHand(roll,1); // Count and
sum up the ones||
|| System.out.print( handScore );||
|| pokerHand = whichPokerHand(roll); // Figure
out which hand we have||
|| System.out.print( " --> " + pokerHand );||
|| bonus = bonusFromPokerHand(roll); //
Determine points the points for the hand||
|| System.out.print( "(+" + bonus + ") --> ");||
|| totalScore = totalScore + handScore + bonus; //
Accumulate total points||
|| System.out.println( totalScore );||
|| }||
|| else {||
|| System.out.println( roll );||
|| }||
|| }||
|
Then below this there are five more loops (for 2, 3, 4, 5, 6) and after
that I have all my static methods.
Hope this helps some of you make progress before class on Friday.
--
Andrew J. Pounds, Ph.D. (pounds_aj at mercer.edu)
Professor of Chemistry and Computer Science
Mercer University, Macon, GA 31207 (478) 301-5627
http://faculty.mercer.edu/pounds_aj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://theochem.mercer.edu/pipermail/csc204/attachments/20161102/c62b8959/attachment.html>
More information about the csc204
mailing list