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: How to implement YAHTZEE game in java using switch statements?

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

    Exclamation How to implement YAHTZEE game in java using switch statements?

    I have to create a source code in JAVA for scoring in the game Yahtzee
    I have no idea where to start
    It has to have a switch statement and if-else statements
    here is what I have so far
    public class Yahtzee {
     
      // constants that specify categories on the scoresheet
      public static final int ONES = 1;
      public static final int TWOS = 2;
      public static final int THREES = 3;
      public static final int FOURS = 4;
      public static final int FIVES = 5;
      public static final int SIXES = 6;
      public static final int THREE_OF_A_KIND = 9;
      public static final int FOUR_OF_A_KIND = 10;
      public static final int FULL_HOUSE = 11;
      public static final int SMALL_STRAIGHT = 12;
      public static final int LARGE_STRAIGHT = 13;
      public static final int YAHTZEE = 14;
      public static final int CHANCE = 15;
     
      /**
       * Calculates the score for a given turn.
       * 
       * @param category selected by the player
       * @param dice current values of the dice
       * @return number of points, or 0 if N/A
       */
      public static int calculateScore(int category, Dice dice) {
        int die1;
        int die2;
        int die3;
        int die4;
        int die5;
     
         die1 = (int)(Math.random() * 6) + 1;
        die2 = (int)(Math.random() * 6) + 1;
        die3 = (int)(Math.random() * 6) + 1;
        die4 = (int)(Math.random() * 6) + 1;
        die5 = (int)(Math.random() * 6) + 1;
     
     
     
        int score;
        score = 0;
        switch(score)
        {
          case ONES:
            break;
          case TWOS:
            break;
          case THREES:
            break;
          case FOURS:
            break;
          case FIVES:
            break;
          case SIXES:
            break;
          case THREE_OF_A_KIND:
            break;
          case FOUR_OF_A_KIND:
            break;
          case FULL_HOUSE:
            break;
          case SMALL_STRAIGHT:
            break;
          case LARGE_STRAIGHT:
            break;
          case YAHTZEE:
            break;
          case CHANCE:
            break;
     
            return score;
        }
      }
         public static int oneValue(int value, Dice dice) {
            return 0;
        }
     
        public static int threeOfAKind(Dice dice) {
            return 0;
        }
     
        public static int fourOfAKind(Dice dice) {
            return 0;
        }
     
        public static int fullHouse(Dice dice) {
            return 0;
        }
     
        public static int smallStraight(Dice dice) {
            return 0;
        }
     
        public static int largeStraight(Dice dice) {
            return 0;
        }
     
        public static int yahtzee(Dice dice) {
            return 0;
        }
     
        public static int chance(Dice dice) {
            return 0;
        }
     
     
      }
    Last edited by Deep_4; November 7th, 2012 at 12:44 PM. Reason: please use [code] tags


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,606
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: SERIOUS HELP YAHTZEE JAVA SOURCE CODE

    First off, please use highlight tags when posting code to preserve formatting.

    Secondly, I recommend you start by reading this: Starting Writing a Program
    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. Note pad source code open instead of executing java program?
    By clalrama in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 26th, 2012, 07:11 PM
  2. Java Source Code to UML Diagrams in NetBeans
    By sarkuzi in forum Threads
    Replies: 3
    Last Post: February 7th, 2012, 11:34 AM
  3. Source Code to Implement Circular Queue in Java
    By rainbow9 in forum Java Programming Tutorials
    Replies: 0
    Last Post: August 20th, 2011, 03:30 AM
  4. Yahtzee code help
    By sarahElizabeth in forum Object Oriented Programming
    Replies: 1
    Last Post: February 17th, 2011, 10:48 AM
  5. Implementing HTML tags in Java Source Code
    By bookface in forum Java Theory & Questions
    Replies: 4
    Last Post: March 19th, 2010, 10:29 PM