Results 1 to 13 of 13
  1. #1
    Nogueirn is offline Member
    Join Date
    Apr 2014
    Posts
    7
    Rep Power
    0

    Default Trouble with a Yahtzee application class

    Hey guys, I'm new to the forum, so excuse my lack of posting etiquette. I've been working on a Yahtzee program, and have finished coding my dice array class (which works perfectly), but my mind seems to escape me on the application class I need to develop. The expected output I need confuses me and I could use some insight. I've attached my expected output and my array class. I also have a GUI that goes along with it, with the only method used is showDice("array") which brings up a window with the dice on it. I understand I need to implement the scanner class of course, but creating the loop for it is a bit confusing. Could anyone help?
    Attached Files Attached Files

  2. #2
    Nogueirn is offline Member
    Join Date
    Apr 2014
    Posts
    7
    Rep Power
    0

    Default Re: Trouble with a Yahtzee application class

    Quote Originally Posted by Nogueirn View Post
    Hey guys, I'm new to the forum, so excuse my lack of posting etiquette. I've been working on a Yahtzee program, and have finished coding my dice array class (which works perfectly), but my mind seems to escape me on the application class I need to develop. The expected output I need confuses me and I could use some insight. I've attached my expected output and my array class. I also have a GUI that goes along with it, with the only method used is showDice("array") which brings up a window with the dice on it. I understand I need to implement the scanner class of course, but creating the loop for it is a bit confusing. Could anyone help?
    I've worked on the program all yesterday and today, and am posting what I have so far. It seems that when I try to add the numbers together with my method, it just takes the original number and displays it. Anyone have any ideas?

    Java Code:
    package proj5;
    import java.util.Scanner;
    
    public class Project5App {
    	
    	public static void main (String[] args)
    	{
    		Scanner sc = new Scanner(System.in);
    		GUI diceTable = new GUI();
    		DiceArray dice = new DiceArray(5);
    		int[] scoreCard = new int[]{0,0,0,0,0,0};
    		int count = 1;
    		
    		for(int j = 1; j < 7; j++)// j: rounds
    		{
    			System.out.println("Round " + j);
    			for (int i = 1; i <= 3; i++)// i: the rolls 
    			{
    				if(i < 3)
    				{
    					System.out.println("Roll " + i + ":");
    					dice.roll();
    					diceTable.showDice(dice);
    					System.out.println("Which die value do you want to keep?");
    					int keep = sc.nextInt();
    					dice.keep(keep);
    				}
    				
    				if (i == 3)
    				{	
    					System.out.println("Roll " + i + ":");
    					dice.roll();
    					diceTable.showDice(dice);
    					System.out.println("Which location would you like to record this round?\nScores:");
    					for(int k = 0; k < 6; k++)//k: score card location
    					{
    						System.out.println(count + "s: " + scoreCard[k] + " points");
    						count++;
    					}
    					count = 1;
    					int location = sc.nextInt();
    					dice.calculateTotal(location);	
    					System.out.println("Round " + j + " complete.");
    					
    					
    					System.out.println(location);
    						
    				}	
    				
    				
    			}
    		}
    
    	}
    		
    		
    		
    }

  3. #3
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,378
    Rep Power
    5

    Default Re: Trouble with a Yahtzee application class

    You need to provide a Short, Self Contained, Correct Example. Also, please explain exactly where the problem is. In other words, the value that is printing out incorrectly and what the value should be.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  4. #4
    Nogueirn is offline Member
    Join Date
    Apr 2014
    Posts
    7
    Rep Power
    0

    Default Re: Trouble with a Yahtzee application class

    Quote Originally Posted by jim829 View Post
    You need to provide a Short, Self Contained, Correct Example. Also, please explain exactly where the problem is. In other words, the value that is printing out incorrectly and what the value should be.

    Regards,
    Jim
    Thanks Jim,

    The value that is printing incorrectly is the value of the calculateTotal method from the DiceArray class. It should be printing out the sum of the values of the dice the user chooses, but is only displaying the value of the number they input.
    Also, the link you provided helps me see what I should post, but I feel I posted what was necessary. Could you possibly be a bit more specific on anything else you need?

  5. #5
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,378
    Rep Power
    5

    Default Re: Trouble with a Yahtzee application class

    Look at the following code.

    Java Code:
    dice.calculateTotal(location); 
    System.out.println("Round " + j + " complete.");
    System.out.println(location);
    You calculate the total for a card location but you don't save it to a value.
    Then later, you just print out the location.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,378
    Rep Power
    5

    Default Re: Trouble with a Yahtzee application class

    In case you aren't sure what I am talking about, you must do it like this.

    Java Code:
    int sum = dice.calculateTotal(location);
    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  7. #7
    Nogueirn is offline Member
    Join Date
    Apr 2014
    Posts
    7
    Rep Power
    0

    Default Re: Trouble with a Yahtzee application class

    Quote Originally Posted by jim829 View Post
    In case you aren't sure what I am talking about, you must do it like this.

    Java Code:
    int sum = dice.calculateTotal(location);
    Regards,
    Jim
    Thank you so much! It's so silly of me to over look something so simple.

    My next question is, how do I get that sum and put it into the proper element in the score card array. Do I need to create another scorecard loop? Or can I insert it into the one I have already, and have it display at the end of the round?

  8. #8
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,378
    Rep Power
    5

    Default Re: Trouble with a Yahtzee application class

    You could place it in your score card by using the index/location/dice value (they are basically the same). One exception is that the index would be one less than the scorecard location (unless you had an array of size 7 so you could use values 1 thru 6 to represent 1's thru 6's).

    But eventually you will need to consider small straight, large straight, full house, etc.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  9. #9
    Nogueirn is offline Member
    Join Date
    Apr 2014
    Posts
    7
    Rep Power
    0

    Default Re: Trouble with a Yahtzee application class

    Quote Originally Posted by jim829 View Post
    You could place it in your score card by using the index/location/dice value (they are basically the same). One exception is that the index would be one less than the scorecard location (unless you had an array of size 7 so you could use values 1 thru 6 to represent 1's thru 6's).

    But eventually you will need to consider small straight, large straight, full house, etc.

    Regards,
    Jim
    Luckily for me, those rules don't apply for this assignment.

  10. #10
    Nogueirn is offline Member
    Join Date
    Apr 2014
    Posts
    7
    Rep Power
    0

    Default Re: Trouble with a Yahtzee application class

    Quote Originally Posted by Nogueirn View Post
    Luckily for me, those rules don't apply for this assignment.
    All i'm trying to do at this point is update the correct element of the array with the sum that I receive from the user. Can anyone help me with that?

  11. #11
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,378
    Rep Power
    5

    Default Re: Trouble with a Yahtzee application class

    I already told you how to do that. What problem are you having?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  12. #12
    Nogueirn is offline Member
    Join Date
    Apr 2014
    Posts
    7
    Rep Power
    0

    Default Re: Trouble with a Yahtzee application class

    Well this is what I have
    Java Code:
    for(int k = 0; k < 6; k++)//k: score card location
    					{
    						if (scoreCard[k] == 0)
    						{
    							System.out.println(count + "s: " + scoreCard[k] + " points");
    							count++;
    							if (location == count)
    								scoreCard[k] = sum;
    						}
    						else
    						{
    							System.out.println("There is already a score for location " + location 
    									+ ". Which location would you like to record this round?");
    						}
    					}
    It still doesn't update the row correctly

  13. #13
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,378
    Rep Power
    5

    Default Re: Trouble with a Yahtzee application class

    Could it be that you your array of size 6 is indexed from 0 to 5 and your dice values are from 1 to 6?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 5
    Last Post: 12-18-2011, 04:06 AM
  2. Replies: 1
    Last Post: 03-08-2011, 09:11 PM
  3. Yahtzee game
    By Vinny2110 in forum New To Java
    Replies: 3
    Last Post: 12-07-2010, 09:49 AM
  4. trouble with a class
    By Alexander Montero in forum New To Java
    Replies: 2
    Last Post: 06-17-2009, 10:01 PM
  5. Small yahtzee program
    By kimmelim in forum New To Java
    Replies: 20
    Last Post: 03-12-2009, 12:11 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
  •