Assig 2
Assig 2
* Joseph Cortez
* Lyndsay Hackett
* Mokhlis Awad
* Ahdia Fuller
*/
import java.util.*;
import java.lang.Math;
/* This prompts the user for input and returns the bet amount as a functional
* legal bet (0 < bet < 100) until it gets one from the user. It must return
* the legal value to the client and not take any other action besides
*/
int bet;
+ " quit?");
bet = keyboard.nextInt();
return bet;
pulled.setString1(firstString);
pulled.setString2(secondString);
pulled.setString3(thirdString);
return pulled;
/* This method produces and returns a single random string based on the
* required probabilities.
*/
{
String pullString = "";
pullString = "7";
pullString = "(space)";
pullString = "cherries";
pullString = "BAR";
else
System.out.println("Fatal ERROR");
return pullString;
*/
public static int getPayMultiplier(TripleString thePull)
int multiplier;
String c = "cherries";
String b = "BAR";
multiplier = 5;
multiplier = 15;
&& thePull.getString3().equals(c))
multiplier = 30;
thePull.getString2().equals(b) &&
thePull.getString3().equals(b))
multiplier = 50;
thePull.getString2().equals("7") &&
thePull.getString3().equals("7"))
multiplier = 100;
}
else multiplier = 0;
return multiplier;
/* This method takes the winnings (a dollar amount) and thePull as parameters
* and displays the three strings inside thePull along with " sorry - you
*/
if(winnings > 0)
System.out.println(thePull.toString());
System.out.println();
else
System.out.println(thePull.toString());
System.out.println();
}
// Main method
int bet = 0;
int m; // Multiplier
int pullWinnings;
TripleString pullString;
// Main loop
do
bet = getBet();
pullString = pull();
m = getPayMultiplier(pullString);
pullWinnings = m * bet;
if (bet != 0)
display(pullString, pullWinnings);
pullString.saveWinnings(pullWinnings);
//End of game
if (bet == 0)
outputResult = pullString.displayWinnings();
int totalWinnings = 0;
while(winningsToken.hasMoreTokens())
totalWinnings = totalWinnings +
Integer.parseInt(winningsToken.nextToken());
System.exit(0);
class TripleString
public TripleString()
{
string1 = "";
string2 = "";
string3 = "";
return true;
else
return false;
if (validString(str) == true)
string1 = str;
return true;
else
{
return false;
return string1;
if (validString(str) == true)
string2 = str;
return true;
else
return false;
return string2;
}
// Modifier for setting private string values
if (validString(str) == true)
string3 = str;
return true;
else
return false;
return string3;
return combinedString;
pullWinnings[numPulls] = winnings;
numPulls++;
return true;
else
return false;
// This method displays the total winnings of the user from the array
if (pullWinnings[i] != -1)
item = Integer.toString(pullWinnings[i]);
}
return result;
101
34
22
34
(space) BAR 7
54
whirrrrrr .... and your pull is ...
56
BAR cherries 7
67
100
100
7 7 BAR
45
76
7 BAR BAR
45
23
87
BAR 7 BAR
34
23
BAR (space) 7
76
87
34
100
7 7 (space)
23
34
54
65
BAR 7 BAR
76
7 BAR BAR
65
54
7 (space) 7
99
0 110 0 2700 0 3350 0 0 0 675 0 2250 115 0 1700 0 0 0 170 0 0 0 345 0 0 0 0 0 0 4950
--------------------------------------------------*/