CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2011
    Posts
    1

    need help with some java coding (beginner) thanks in advance

    heres my problem..

    #
    Create a class called Craps (36 pts)

    * Provide appropriate names and data types for each of the instance variables. Maintain two GVdie objects, current point, credit balance, current message and a boolean value that is set to 'true' when it is legal to come out and set to 'false' when it is not.
    * public Craps ( ) - a constructor that initializes all of the instance variables to appropriate values.
    * public void comeOut ( ) - If it is time to come out, roll both dice. Otherwise, remind the player by setting the message instance variable that it is not time to "come out" but it is time to roll (do not print a message). If the total is 7 or 11, the player wins and an appropriate message is set. If the total is 2, 3 or 12, the player loses and an appropriate message is set. Otherwise, the dice total is set to the "point". The player must have at least one credit to play. Update instance variables as needed.
    * public void roll ( ) - If a point has been set, roll both dice. Otherwise, remind the player to come out first by setting the message. If the total is 7, the player loses and an appropriate message is set (not printed). If the value of the rolled dice equals the "point", the player wins and an appropriate message is set (not printed). Update instance variables as needed.
    * public int getCredits ( ) - return the current credit balance.
    * public boolean okToRoll ( ) - return true if it is time to roll, return false if it is time to come out.
    * public void setCredits (int) - set the credit balance to the provided value. The value must be positive or else the credit remains unchanged.
    * public GVdie getDie (int num) - return the requested die. Legal values for "num" are 1 or 2. Note, this method is only used for the GUI.
    * public String getMessage ( ) - return the internal message. The message takes on different meanings depending on what is happening in the game.


    this is what i have so far

    Code:
    public class Craps
    {
    
       private int die1;
       private int die2;
       private double currentpoint;
       private int creditbalance ;
       private String currentmessage;
       private boolean oktoroll; 
    
       public Craps ( ) {
           
        }
     
          
       private void comeOut() {
        if (oktoroll) {
           Random rand = new Random();
           die1 = rand.nextInt(6) + 1;	       
           die2 = rand.nextInt(6) + 1;
           currentmessage= "Time to come out";
        }
        else {
    	       currentmessage = "Not time to come out";
           
        }
        }
        public void Roll(){
         if (die1+die2!=0){
          currentmessage= "Roll dice";
        }
         else {
          currentmessage= "Time to come out";
        }
          
         
        }
      
        public int getCredits ( ) {
         
         return creditbalance;
    totally stuck from there....

    help would be awesome..

    i know its basic coding, but I am very new.

    thanks a lot .

  2. #2
    Join Date
    May 2005
    Location
    San Antonio Tx
    Posts
    44

    Re: need help with some java coding (beginner) thanks in advance

    this is what i have so far
    I'll point out a few things about your code.

    1) your code is missing two brackets at the end (although it might be because of the copy-paste)
    2) random in comeOut method needs an appropriate package like import java.util.Random;
    3) you need a tester class with a main method in order to test Craps class
    4) you should try to indent your code properly to make it easier to read, you might be able to do that automatically if you are using an editor like eclipse.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured