Homework help--almost done but don't know how my class and main work?

hello, i'm doing a project for my intro to java class. i'm almost done but i'm very confused on making my main and class work. the counter for my class slotMachine keeps resetting after 2 increments. also i don't not know how to make my quarters in the main receive a pay out from my class. Please guide me to understand what i have to do to solve this problem...I have listed my question page and my class and main of what i have done so far. Thank you .I will really appreciate the help.
Objective: Create a class in Java, make instances of that class. Call methods that solve a particular problem Consider the difference between procedural and object-oriented programming for the same problem.
Program Purpose:
Find out how long it will take Martha to lose all of her money playing 3 instances of the slot machine class.
Specification: Martha in Vegas
Martha takes a jar of quarters to the casino with the intention of becoming rich. She plays three machines in turn. Unknown to her, the machines are entirely predictable. Each play costs one quarter. The first machine pays 30 quarters every 35th time it is played; the second machine pays 60 quarters every 100th time it is played; the third pays 11 quarters every 10th time it is played. (If she played the 3rd machine only she would be a winner.)
Your program should take as input the number of quarters in Martha's jar (there will be at least one and fewer than 1000), and the number of times each machine has been played since it last paid.
Your program should output the number of times Martha plays until she goes broke.
Sample Session. User input is in italics
How many quarters does Martha have in the jar?
48
How many times has the first machine been played since playing out?
30
How many times has the second machine been played since paying out?
10
How many times has the third machine been played since paying out?
9
Martha plays XXX times
Specific requirements: You must solve this using an object-oriented approach. Create a class called SlotMachine. Think about: What does a SlotMachine Have? What does it do? What information does it maintain? This is the state and behavior of the object. Each instance of this class will represent a single slot machine. Don�t put anything in the class unless it �belongs� to a single machine.
In the main method, create 3 instances of the slot machine to solve the problem in the spec. Play the machines in a loop.
========================================================================
my class
========================================================================
public class SlotMachine{
private int payOut;
private int playLimit;
private int counter;
public SlotMachine (int payOut, int playLimit){
this.payOut = payOut;
this.playLimit = playLimit;
public void setPayOut (int payOut){
this.payOut = payOut;
public int getPayOut(){
return payOut;
public void setPlayLimit (int playLimit){
this.playLimit = playLimit;
public int getPlayLimit(){
return playLimit;
public void slotCounter(){
counter = SavitchIn.readLineInt();
public int game(){
counter++;
if (counter == playLimit){
counter = 0;
return payOut - 1;
return -1; // the game method was edited by my professor but i'm still confused to make it work
=======================================================================
my main
=======================================================================     
public class Gametesting{
public static void main(String[]args){
SlotMachine firstSlotMachine = new SlotMachine (2,3);
SlotMachine secondSlotMachine = new SlotMachine (2,3);
SlotMachine thirdSlotMachine = new SlotMachine (2,2);     
int quarters;
int playerCount = 0;
System.out.println("How many quarters does Martha have in the jar?");
quarters = SavitchIn.readLineInt();
System.out.println("How many times has the first machine been played since paying out?");
firstSlotMachine.slotCounter();
System.out.println("How many times has the second machine been played since paying out?");
secondSlotMachine.slotCounter();
System.out.println("How many times has the third machine been played since paying out?");
thirdSlotMachine.slotCounter();
while (quarters != 0){
playerCount++;
quarters--;
firstSlotMachine.game();
if (quarters != 0){
playerCount++;
quarters--;
secondSlotMachine.game();
if (quarters != 0){
playerCount++;
quarters--;
thirdSlotMachine.game();
System.out.println("Martha plays " + playerCount + " times");

The main problem is that you made the first and second slot machine to pay out 2 quarters after 3 games and the third machine pay out two quarters after two games. That is not what your assignment specified.
SlotMachine firstSlotMachine = new SlotMachine (2,3);
SlotMachine secondSlotMachine = new SlotMachine (2,3);
SlotMachine thirdSlotMachine = new SlotMachine (2,2);
The second problem is that you never add the payout of a machine to Martha's number of quarters.
Look carefully at the way your professor implemented the game() method. If you think about it, what it returns is the net "gain" from playing a game. On jackpot it returns payOut -1 (jackpot less the one quarter Martha had to pay for the game), otherwise it returns -1 (Martha spends one quarter and wins nothing).
So what you can do is simply add the returned value to the number of quarters in the jar -
quarters = <machine>.game();
instead of quarters--.

Similar Messages

Maybe you are looking for