Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Couple compile errors for dice game

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Couple compile errors for dice game

    Cannot get this thing to compile at all. Supposed to make a game where you start off with $10 and bet to get doubles on dice. If you win you double you're money and if you lose, well you lose you're money, lol.

    <import java.util.Random;
     
    	public class Die
    	{
    	      private int faceValue;
    	      private final int MAX = 6;
    	      private Random dieGen;
     
    	      public Die()
    	      {
    	        faceValue = 1;
    			  dieGen = new Random();
    	      }
     
    	      //Math.random creates random integers from 1 - 6
    	      public void roll()
    	      {
    				faceValue = dieGen.nextInt(MAX) + 1;
    	      }
     
    	      //Sets the face value
    	      public void setFaceValue(int value)
    	      {
    	        faceValue = value;
    	      }
     
    	      //Gets the face value using the setFaceValue method
    	      public int getFaceValue()
    	      {
    	        return faceValue;
    	      }
     
    		 public static void main (String[] args )
    	    {
    	        Die d1, d2;
     
    	        // Creates two Die objects
    	        d1 = new Die();
    	        d2 = new Die();
     
    	        d1.roll();
    	        d2.roll();
     
    	// Compare to see if faces equal  
       public boolean isSame()
    	  {
    	   if (d1.equals(d2))
    		{
    			return true;
    			}
       }
     
    	      //Converts values into a String
    	      public String toString()
    	      {
    	        String result = d1 + " and " + d2;
     
    	        return result;
    	      }
     }		  
     
     
    >

    <import java.util.Random; 
    import java.util.Scanner; 
     
    	public class DoublesGame
    	{ 
    		public static void main(String args[])
    		{ 
     
    			Scanner input = new Scanner(System.in); 
     
    			//Instance Variables
    			int money = 10; 
    			int offer;
    			// Create new dice
    			d1 = new Die();
    			d2 = new Die();
     
    			//Amount of money and betting			
    			while(money>0 || money>1000)
    			{ 
     
    				System.out.println("You have $" + money); 
     
    				System.out.println("How much would you like to bet?"); 
     
    				offer = input.nextInt(); 
     
    				money = money - offer; 
     
    			// Display the result
    			System.out.println("You rolled a " + d1 " and " + d2);
    			}
     
    			if(d1 == d2)
    			{
    			gained = offer * 2;
     
    			system.out.println("You win $" + gained);
    			}
     
    			// After you run out of money
    			if(money<0)
    			{ 
    				System.out.println("Better luck next time"); 
     
    			} 
    		} 
    	}>


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Couple compile errors for dice game

    And what are your compiler errors?

    Each compiler error should tell you what line it's on. Take a look at that line. Is it missing something? Does it contain something extra?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Remaining compile errors: no suitable method found for & cannot find symbol
    By ChuckLep in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 12th, 2011, 03:33 PM
  2. Dice game code creating help!
    By kodols in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 22nd, 2011, 07:01 PM
  3. Dice Wagering Game new to Multiple Classes
    By Laxman2809 in forum What's Wrong With My Code?
    Replies: 24
    Last Post: September 16th, 2011, 08:22 PM
  4. Dice Game help and Arrays
    By SnarkKnuckle in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 9th, 2011, 10:08 PM
  5. Dice game help, a little cleanup
    By SnarkKnuckle in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 28th, 2011, 12:28 PM