Problem with Roulette Program


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Problem with Roulette Program

  1. #1
    Join Date
    May 2006
    Posts
    1

    Problem with Roulette Program

    i have a problem with this program. Please help. The problem is in the last if statement. I get the following error:
    • operator % cannot be applied to Wheel, int


    The below is the program, and after it is the class
    Code:
    import cs1.Keyboard; 
    
    public class Roulette
    {
    	public static void main (String [] args)
    	{
    
    	Wheel spin= new Wheel(); 
    	double initialmoney= 100; 
    	
    	
    	System.out.println("Welcome to Roulette!"); 
    	System.out.println("You start off with $" + initialmoney + "\n Please select how much you would like to bet: ");
    	int bet= Keyboard.readInt();
    	
    	System.out.println("Where would you like to place your bet? (Enter Designated Number) \n\t Evens=1 \n\t Odds=2 \n\t Blacks=3 \n\t Reds=4 \n\t First 12=5 \n\t Second 12= 13 \n\t Third 12= 14 \n\t -1 or 0=15 \n\t or a Specific Number: ");
    	int guess= Keyboard.readInt(); 
    	
    	if(guess==1)
     		{ if(spin%2==0);}}}
    this is the class
    Code:
    import java.util.Random;
    public class Wheel
    {
    	private double spin; 
    	
    	public Wheel ()
    	{
    		getwheel (); 
    	}
    	
    	public void getwheel ()
    	{
    		spin= (double) (Math.random() * 36); 
    	}
    	
    	public String toString()
    	{
    	
    	String wheelSpin= ""; 	
    	if (spin==1)
    		wheelSpin = "1- Red";
    	else if (spin==2)
    		wheelSpin = "2- Black";		
    	else if (spin==3)
    		wheelSpin = "3- Red";	
    	else if (spin==4)
    		wheelSpin = "4- Black";
    	else if (spin==5)
    		wheelSpin = "5- Red";		
    	else if (spin==6)
    		wheelSpin = "6- Black";
    	else if (spin==7)
    		wheelSpin = "7- Red";
    	else if (spin==8)
    		wheelSpin = "8- Black";
    	else if (spin==9)
    		wheelSpin = "9- Red";
    	else if (spin==10)
    		wheelSpin = "10- Black";		
    	else if (spin==11)
    		wheelSpin = "11- Black";
    	else if (spin==12)
    		wheelSpin = "12- Red";
    	else if (spin==13)
    		wheelSpin = "13- Black";
    	else if (spin==14)
    		wheelSpin = "14- Red";
    	else if (spin==15)
    		wheelSpin = "15- Black";		
    	else if (spin==16)
    		wheelSpin = "16- Red";		
    	else if (spin==17)
    		wheelSpin = "17- Black";
    	else if (spin==18)
    		wheelSpin = "18- Red";
    	else if (spin==19)
    		wheelSpin = "19- Red";
    	else if (spin==20)
    		wheelSpin = "20- Black";
    	else if (spin==21)
    		wheelSpin = "21- Red";
    	else if (spin==22)
    		wheelSpin = "22- Black";
    	else if (spin==23)
    		wheelSpin = "23- Red";
    	else if (spin==24)
    		wheelSpin = "24- Red";
    	else if (spin==25)
    		wheelSpin = "25- Red";
    	else if (spin==26)
    		wheelSpin = "26- Black";
    	else if (spin==27)
    		wheelSpin = "27- Red";
    	else if (spin==28)
    		wheelSpin = "28- Black";
    	else if (spin==29)
    		wheelSpin = "29- Black";
    	else if (spin==30)
    		wheelSpin = "30- Red";
    	else if (spin==31)
    		wheelSpin = "31- Black";
    	else if (spin==32)
    		wheelSpin = "32- Red";
    	else if (spin==33)
    		wheelSpin = "33- Black";
    	else if (spin==34)
    		wheelSpin = "34- Red";
    	else if (spin==35)
    		wheelSpin = "35- Black";
    	else if (spin==36)
    		wheelSpin = "36- Red";
    	
    	String wheelresult = (wheelSpin); 
    	return wheelresult; }
    }

  2. #2
    Join Date
    Mar 2006
    Posts
    37
    If you don't mind I would like to make one quick suggestion. I would have used a switch statement instead of using all of those if else statements.

  3. #3
    Join Date
    Jul 2005
    Posts
    78
    One problem with your code there is that you're never going to get 36.

    Math.random() generates numbers from 0 (inclusive) to 1 (exclusive) ie [0,1)

    Also, why have you got spin as a double when you're only interested in integer values?


    .

    Is your entire program replicated in the first code box? It doesn't look like it to me....

Similar Threads

  1. Floating Point Addition Problem
    By pdavila in forum C++
    Replies: 5
    Last Post: 05-11-2006, 10:52 AM
  2. How can I build copy protection into my program
    By W.Pierce in forum VB Classic
    Replies: 1
    Last Post: 12-11-2001, 08:28 AM
  3. The invisible program
    By James Abbott in forum VB Classic
    Replies: 0
    Last Post: 11-24-2001, 01:42 AM
  4. Replies: 0
    Last Post: 12-15-2000, 10:07 PM
  5. Problem In Java Mail Program
    By Rajeev Iyer in forum Java
    Replies: 1
    Last Post: 11-22-2000, 06:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center