5 Replies - 693 Views - Last Post: 28 September 2012 - 10:09 PM Rate Topic: -----

#1 baothai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-September 12

Dice Program - Not sure how to continue

Posted 28 September 2012 - 06:49 PM

I have this program I have to do for intro to programming. I have half the psuedocode ready but I am the type of person who starts the program and write out psuedocode, but that is just me, because that is how I understand it. But the program I have to make for my class is
"Modify your dice program to incorporate the input of a point offering and the player expected roll. Each game will begin with 20 points. The play will continue playing until the points account balance reaches 100 or the balance reaches 0. The maximum point offering allowed by the player will be 6 points. Based on the player roll, calculate the points gained from the table below. Add the calculated point return to the final points account roll does not match the expectation the player will loose their point offering."
Posted Image

My code I started so far, I am using eclipse and javascript
 /**
 * 
 */

/**
 * @author Bao
 *
 */
public class DiceGaming {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int pointbalance = (20);
		byte offering;
		String name;
		byte expecting;
		byte newOffering;
		byte newExpecting;
		byte dice1 = (byte) ((byte)(Math.random()*6) + 1);
		byte dice2 = (byte) ((byte)(Math.random()*6) + 1);
		byte totalroll = (byte) (dice1 + dice2);
		
		System.out.println("What is your name?");
		name = TextIO.getlnString();
		System.out.println("Your point balance is " + pointbalance);
		
		while (pointbalance > 0 || pointbalance <100){
			System.out.println("What is your offering?");
			offering = TextIO.getByte();
			
			if (offering > 6){
				System.out.println("Please enter a value less than 6");
				newOffering = TextIO.getByte();
				offering = newOffering;
				pointbalance = pointbalance - offering;
				System.out.println("Your new balance is " + pointbalance);
			}else 
				System.out.println("What are you expecting to roll? (You have 2 dice)");
				expecting = TextIO.getByte();
				
				if (expecting > 12 || expecting == 0){
					expecting = (Byte) null;
					System.out.println("You have to choose between 2 through 12");
					System.out.println("Please re-enter a new number");
					newExpecting = TextIO.getByte();
					expecting = newExpecting;
					
				
					}
					System.out.println("Your first roll from Dice 1 is " + dice1);
					System.out.println("Your second roll from Dice 2 is " + dice2);
					System.out.println("Your total roll is " + totalroll);
					if (totalroll = 2 || 12){
						pointbalance = pointbalance + (4*offering);
					}else if (totalroll = 3 || 11){
						pointbalance = pointbalance + (3*offering);
					}else if (totalroll = 4 || 10){
						pointbalance = pointbalance + (2*offering);
					}else if (totalroll = 5 || 9){
						pointbalance = pointbalance + ((3 /2) * offering );
					}else if (totalroll = 6 || 8){
						pointbalance = pointbalance + ((6/5) * offering);
					}else if (totalroll = 7){
						pointbalance = pointbalance + (1*offering);
					
						if (expecting == totalroll){
							System.out.println("Your expected roll " + expecting + " equals to " + totalroll);
						
			
		
						}
		}

	}
}
} 


The picture suppose to represent this, so its like gambling, if I bet this and I expect this to come out, and if what I was expecting comes out, I get "return" amount back

					if (totalroll = 2 || 12){
						pointbalance = pointbalance + (4*offering);
					}else if (totalroll = 3 || 11){
						pointbalance = pointbalance + (3*offering);
					}else if (totalroll = 4 || 10){
						pointbalance = pointbalance + (2*offering);
					}else if (totalroll = 5 || 9){
						pointbalance = pointbalance + ((3 /2) * offering );
					}else if (totalroll = 6 || 8){
						pointbalance = pointbalance + ((6/5) * offering);
					}else if (totalroll = 7){
						pointbalance = pointbalance + (1*offering); 


Is This A Good Question/Topic? 0
  • +

Replies To: Dice Program - Not sure how to continue

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10364
  • View blog
  • Posts: 38,378
  • Joined: 27-December 08

Re: Dice Program - Not sure how to continue

Posted 28 September 2012 - 06:54 PM

Moved to Java. Please note that Java != Javascript.

Your image is too small that we cannot really see it. Can you post the output you are encountering vs. the output you are expecting?
Was This Post Helpful? 0
  • +
  • -

#3 baothai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-September 12

Re: Dice Program - Not sure how to continue

Posted 28 September 2012 - 07:08 PM

View Postmacosxnerd101, on 28 September 2012 - 06:54 PM, said:

Moved to Java. Please note that Java != Javascript.

Your image is too small that we cannot really see it. Can you post the output you are encountering vs. the output you are expecting?


Well, I'm not sure what to expect since I am new to programming and the coding is not finished but I can tell you what I want the program to do

 //your starting balance is 20 points
//while balance is under 100 or above 0, play the game below
//you have to bet however many points you want
//the bet can not be over 6, if it is, please re-enter a new value
//then subtract the offering from current point balance
//then ask what is the expecting number that dice gonna roll
//the 2 dice are rolled and add up
//check if the sum of the 2 rolled equal to the expecting number
//if it does, and  they are either 2 or 12, you get 4 points in return per 1 point offered
//if it came out either 3 or 11, you get 4 points in return per 1 point offered
//if it came out either 4 or 10, you get 3 points in return per 1 point offered
//if it came out 5 or 9, you get 3 points per 2 point offered
//if it came out 6 or 8, you get 4 points per 3 point offered
//if it came out 7, you get 1 point per 1 point offered
//if it doesn't, return "Your expecting number was wrong"
//the game has to keep going until the player reaches 100 or 0
//if player reaches 100, print you won!, if reaches 0, print game over




I'm not sure if that is the whole pseudocode, just giving the basic
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10364
  • View blog
  • Posts: 38,378
  • Joined: 27-December 08

Re: Dice Program - Not sure how to continue

Posted 28 September 2012 - 07:11 PM

So run your program, bet 1 point, and see what happens. Run it a few times to get a feel for the various cases. You need to be able to tell us:
-What it is currently doing
-What it is supposed to do
-How what it is currently doing deviates from what it is supposed to do
Was This Post Helpful? 0
  • +
  • -

#5 baothai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-September 12

Re: Dice Program - Not sure how to continue

Posted 28 September 2012 - 07:19 PM

View Postmacosxnerd101, on 28 September 2012 - 07:11 PM, said:

So run your program, bet 1 point, and see what happens. Run it a few times to get a feel for the various cases. You need to be able to tell us:
-What it is currently doing
-What it is supposed to do
-How what it is currently doing deviates from what it is supposed to do


What it is currently doing -
1. Ask for the name √
2. Ask for the offering √
3. If the input is over 6, ask for new input √
4. Print out new balance after subtracting the offering from balance √
5. Asking what expected to roll √
6. Print out what is rolled √
7. if it does, and they are either 2 or 12, you get 4 points in return per 1 point offered
if it came out either 3 or 11, you get 4 points in return per 1 point offered
if it came out either 4 or 10, you get 3 points in return per 1 point offered
if it came out 5 or 9, you get 3 points per 2 point offered
if it came out 6 or 8, you get 4 points per 3 point offered
if it came out 7, you get 1 point per 1 point offered
(not sure if it works since it haven't match once)
8. Prints out step 2 again ( x )
9. Balance is the same after running the program the second time ( x )



What it is supposed to do -
8. Print out either the roll matched with expected or not
9. It suppose to go from 20, and after offering 5, then go down to 15, and when restart the process, suppose to go from 15, to 10


How it is different -
8 vs 8 - It suppose to print out the result first before asking for the offering again
9 vs 9 - It suppose to go from 20 and keep on subtracting, instead of moving back to 20 after the statement




Thats all I got so far, not done with the coding
Was This Post Helpful? 0
  • +
  • -

#6 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: Dice Program - Not sure how to continue

Posted 28 September 2012 - 10:09 PM

None of your if statements beginning at line 56 are correct. Aren't you getting errors or seeing the errors in Eclipse before compiling?

Java is not Javascript.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1