This is one of four major individual assignments that you are required to complete in this class. You MUST design and code this project on your own. You can ask for debugging help, particularly from the tutors, TA or instructor, but this project is to be your own work. The project relies on knowledge and skills that you will develop in Recitation Laboratories 1, 2, and 3. If you are having trouble with these recitations after your in-class session, please be sure that you come to the lab at another time and sit down with a tutor.
SlotMachine.java
and SlotMachineMain.java
"Orange", "Lemon", "Cherry"
and "Wild". If all three strings are the same, the player
wins, otherwise the player loses.
A "Wild" matches any of the four other
choices. The slot machine also keeps track of the number of games
won, lost, and played.
You will develop a SlotMachine class to represent the
slot machine and a SlotMachineMain to test the SlotMachine
and play the games.
SlotMachine ClassString values: fruit1, fruit2, and fruit3
containing the choices that were randomly pickedboolean value myResult indicating whether the game
was won or lost.int counters: myGamesWon, myGamesLost,
myTotalGames representing the number of games won, the number
of games lost, and the total number of games played.String values are initialized by calling the private
helper method getFruitmyResult is initialized to falsegetResult, getGamesWon,
getGamesLost, and getGamesPlayed
methods do the expected things.
getPercentWon method calculates the percentage won and returns
this value
as a doubletoString method returns the games won, games lost, games played,
percentage of games won. You should use the getPercentInstance
located in the NumberFormat class for this. (See p. 89
of the textbook for
an example.)pull() method makes three calls to getFruit (one for each of
the three choices) and stores the returning value in the appropriate variables.
It then decides if the game was won or lost using the specifications described
above. The appropriate counters should be updated. Call
the private helper method displayResults described below.getFruit method uses the random method in the Math
class to pick a number between 0 and 3 inclusive. It will then use
a switch statement to determine which choice was made and return
it as a String.displayResults method prints the three choices and if the game
was won or lost. This can be done by testing the boolean
value myResult.
SlotMachineMain Class for testing:SlotMachine and name it slot1pull methodtoString methodSlotMachine and name it slot2 pull methodtoString methodgetPercentWon
for each machine and printing the appropriate message.
If a tie results tell the player
to play either machine.