Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Roulette Game(spots, bets, and winnings)

$
0
0
Hello, I'm doing an assignment for school and could use some help.
Here is what I am currently working on:
The RouletteTable class contains all the possible bet spots (several RouletteSpot objects) as private instance variables. The ones required for this assignments are:
odd, even, red, black (each have 1:1 payoff) (NOTE: 0 is NONE of these)

1st third (1-12), 2nd third (13-24), and 3rd third (25-36) (each have 2:1 payoff)
an array of RouletteSpot objects for 0 to 36, inclusive (each have 35:1 payoff).
Include a public instance method for initializing all RouletteSpot's bet to 0. Include public instance methods for assigning a bet to each of the above RouletteSpots (calling its mutator). You should have one method with another parameter for the number RouletteSpot (0-36). Include public instance methods for returning the winnings for each spot.

I have completed all of the above to the best of my ability and what I think is right:
public class RouletteTable {

	private RouletteSpot odd, even, red, black;
	private RouletteSpot firstThird, secondThird, thirdThird;
	private RouletteSpot[] spotArray = new RouletteSpot[37];
	
	public void initializeBet(){
		odd = new RouletteSpot(1);
		even = new RouletteSpot(1);
		red = new RouletteSpot(1);
		black = new RouletteSpot(1);
		firstThird = new RouletteSpot(2);
		secondThird = new RouletteSpot(2);
		thirdThird = new RouletteSpot(2);
		
		for(int i = 0; i < 37; i++){
			spotArray[i] = new RouletteSpot(35);
	}			
}
	
	public void assignBet1(int bet, String locn){
		if(locn == "odd")
			odd.setBet(bet);
		if(locn == "even")
			even.setBet(bet);
		if(locn == "red")
			red.setBet(bet);
		if(locn == "black")
			black.setBet(bet);
	}
	public void assignBet2(int bet, int locn){
		if(locn >= 1 && locn <= 12)
			firstThird.setBet(bet);
		if(locn >= 13 && locn <= 24)
			secondThird.setBet(bet);
		if(locn >= 25  && locn <= 36)
			thirdThird.setBet(bet);
		else
			System.out.println("Location out of range!");
	}
	public void assignBet3(int bet, int locn){
		if(locn >= 0 && locn <= 36)
			spotArray[locn].setBet(bet);
		else
			System.out.println("Location out of range!");
	}
	public int returnWinnings1(String locn){
		int amountWon = 0;
		if(locn == "odd")
			amountWon = odd.returnWinnings();
		if(locn == "even")
			amountWon = even.returnWinnings();
		if(locn == "red")
			amountWon = red.returnWinnings();
		if(locn == "black")
			amountWon = black.returnWinnings();
		return amountWon;
	}
	public int returnWinnings2(int locn){
		int amountWon = 0;
		if(locn >= 1 && locn <= 12)
			amountWon = firstThird.returnWinnings();
		if(locn >= 13 && locn <= 24)
			amountWon = secondThird.returnWinnings();
		if(locn >= 25  && locn <= 36)
			amountWon = thirdThird.returnWinnings();
		return amountWon;
	}
	public int returnWinnings3(int locn){
		int amountWon = 0;
		amountWon = spotArray[locn].returnWinnings();
		return amountWon;
	}
}


And the RouletteSpot class:

public class RouletteSpot {

	private int payoff = 1;
	private int userBet;
	
	
	public RouletteSpot(int payoff){
		this.payoff = payoff;
		userBet = 0;
		
	}
	public int getUserBet(){
		return userBet;
	}
	public int getPayOff(){
		return payoff;
	}
	public void setBet(int userBet) {
		    if (userBet >= 0) {
		       this.userBet = userBet; 
		    }
		}

	
	public int returnWinnings(){
		
		return payoff*userBet + userBet;
	}
	
}



If someone could be so kind as to double check my code and let me know if anything needs fixing or improving, I would greatly appreciate it!
I would much rather catch my mistakes early in the code than go through a huge debugging process later on.
Thank you for your time!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>