Results 1 to 7 of 7
Thread: Roulette Wheel Quick Help
- 10-29-2012, 01:42 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
Roulette Wheel Quick Help
So, I've fairly far along on a project for school but would love some sort of direction. We haven't used arrays yet so I'd like to avoid using if possible but my question is the following. I've simulating 1000 rolls on the roulette wheel and need to give summary at the end of how many times it landed on red, black, odd and even. the problem is that 1-10 reds are odd numbers and black are even numbers; 11-20 reds are even and black are odd. I really don't want the answer but just a hint as to how I can arrange it to run like that. Obviously, I could write a bunch of if and elses but I would like to be as clever as possible in answering. thanks in advance.
Maybe I'm not that far along but here is what I'm at so far:
import java.util.Random;
import java.util.Scanner;
public class Roulette
{
public static void main(String[] args)
{
//Local declarations
Scanner keyboard = new Scanner(System.in);
Random generator = new Random();
int green=0;
int red=0;
int black=0;
int even=0;
int odd=0;
int rouletteNum=0;
System.out.println("Welcome to the Roulette\n");
for (int roll = 1; roll <=10000; roll++)
{
rouletteNum = generator.nextInt(39); //0-38
if (rouletteNum == 0)
green++;
else if (rouletteNum <= 10)
red++;
else if (rouletteNum <= 18)
black++;
else if (rouletteNum <= 28)
even++;
else odd++;
}
System.out.println ("Green =" + green);
System.out.println ("Red =" + red);
System.out.println ("Black =" + black);
System.out.println ("Odd =" + odd);
System.out.println ("Even =" + even);
}
}Last edited by jcharhyde; 10-29-2012 at 01:44 AM.
- 10-29-2012, 01:56 AM #2
Re: Roulette Wheel Quick Help
Simple way to see if a number is odd or even is to mod it by 2. If the result is 0 then it is even. Do that and you only have to work out if it is black or red.
- 10-29-2012, 02:04 AM #3
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
Re: Roulette Wheel Quick Help
ahh sorry for my ignorance but what do you mean mod it by two? divide the number you mean? sorry thanks for the reply man
- 10-29-2012, 02:36 AM #4
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
Re: Roulette Wheel Quick Help
also had one more question, this is part of my code:
else if (num==1||num==3||num==5||num==7||num==9||num==19|| num==21||num==23||num==25||num==27)
red++;
is there any way to red++ and odds++ in that same statement? i can one or the other to increase but not at the same time?
- 10-29-2012, 02:42 AM #5
Re: Roulette Wheel Quick Help
1. You didn't bother to reply to the two responses on your first thread Comparing 3 int value and ordering descendingly . Not the best way to continue to get free help on a forum, that.
2. Please go through Guide For New Members and BB Code List - Java Programming Forum and edit your posts accordingly.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 10-29-2012, 02:50 AM #6
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
Re: Roulette Wheel Quick Help
My apologies to all for the bad form. I did read over the guide for new members when I registered. I find this site and forum resourceful even though I rarely make posts myself. I'll reread the guidelines and ensure I don't make the same mistakes in the future. Thank you and again, sorry for the trouble.
- 10-31-2012, 12:29 AM #7
Similar Threads
-
The Roulette Ready Insurrection
By wemoAffininna in forum Java SoftwareReplies: 0Last Post: 01-07-2012, 08:57 AM -
How To Make Wheel Look Like It's Moving?
By kraigballa in forum Java AppletsReplies: 4Last Post: 10-14-2011, 05:50 AM -
Roulette game help
By linc186 in forum New To JavaReplies: 6Last Post: 03-14-2011, 12:47 AM -
online ROULETTE CALCULATER
By dysfunktional in forum Java AppletsReplies: 2Last Post: 05-13-2009, 09:49 AM -
I am trying to create a wheel that has 5 spokes...
By fernando in forum Java 2DReplies: 1Last Post: 08-07-2007, 06:59 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks