Results 1 to 8 of 8
  1. #1
    Aziombi is offline Member
    Join Date
    Feb 2013
    Posts
    5
    Rep Power
    0

    Question okay so i need a little help with my program.

    heres the program i was assigned to write :
    Create a DiceGame.java which does the following:

    -
    -
    -
    -

    Allot the user $10.00 of “pretend” money to play the game.
    Let the user play the game until they enter the word “done”, or they run out of money.
    The game rolls 2 dice each time. The values of each dice are added up to get the total value of the roll.
    The user should always be presented the following choices:

    Choice:
    even
    odd
    fib
    double
    exact

    done

    Meaning:
    The total roll is going to be even
    The total roll is going to be odd
    The total roll is a Fibonacci number
    The two dice will have the same number
    The user is able to specify the exact dice roll
    (you will have the prompt the user for a roll amount)
    quit program

    Fixed bet amount:
    $0.50
    $0.50
    $1.00
    $2.00
    Allow user to enter amount

    -

    If the user does not have enough money to choose “double” or “exact” then print out “not enough money for this
    bet” and loop again.
    Before each roll, the program should display the amount of money the user has and the above choice list.
    After each roll, it should display the actual roll. If the user won or lost, randomly display a winning message (like
    “Hooray – you in da money!”) or losing message (like “Better luck next time, pal!”.
    o You must create two text files:
     winningmessages.txt – which contains 10 winning messages that you make up yourself
     losingmessages.txt – which contains 10 losing messages that you make up yourself.
    o Your program must read in both of these text files and store the messages in two separate arrays of
    strings.
    o After each roll, your program must display one of these messages randomly to the user.
    o NOTE: We will not cover in class how to read in text files! As part of this assignment, you must figure
    this out on your own by using your textbook or an online resource/API. You can only use an online
    resource for this aspect of this program!!
     HINT: You should use a Scanner object to read each text file. Use a for loop that iterates 10
    times to read in each message.

    -
    -
    iv been working on it for a few hours and im stuck .. here is what i have so far...
    Java Code:
    import java.util.*;
    import java.util.Scanner;
    public class DiceGame{
    public static void main(String[] args) {
    System.out.println("Wecome! You have been given $10.00 to play, use this money to place a bet.");
    System.out.println("These are the rules (and also commands)to play the game: ");
    System.out.println("You can play until you run out of the free money I gave you, or you can quit by entering the word (done).");
    System.out.println("The game rolls 2 dice each time. The values of each dice are added up to get the total value of the roll.");
    System.out.println("Those are the rules, Good Luck!");
    
    String s1= "even";
    String s2= "odd";
    String s3= "fib";
    String s4= "double";
    String s5= "exact";
    double cash = 10.00;
    int exactbet = 0;
    
    while (cash > exactbet){
       System.out.println(" How would you like to bet?");
    	System.out.println(" even, odd , fib , double , or exact are your choices, enter your choice now : ");
    	Scanner input = new Scanner(System.in);
    	String choice = input.nextLine();}
    	
    
    
    if (choice.equals("even")){
    double bet = .50;
    //roll dice
    //compare to see if it is even
    //if even show winning text and add money to cash
    //if not even show losing text and take off.50
    
    
     
    
    
    
    
    System.out.println("Cash left: " + cash);
    
    
    	if (choice.equals("even") || choice.equals("odd")){
    	double bet = .50;
    	if (bet > cash){
    	System.out.println("not enough cash");
    	System.exit(0);}
    	}
    	
    	
    	if (choice.equals("fib")){
    	double bet = 1.00;
    	if (bet > cash){
    	System.out.println("not enough cash");
    	System.exit(0);}
    	}
    		}
    	if (choice.equals("double")||choice.equals("exact")){
       double bet = 2.00;
    	if (bet > cash){
    	System.out.println("not enough cash");
    	System.exit(0);}
    	if (choice.equals("exact")){
    	System.out.println("Enter exact number to bet on: ");
    	exactbet = input.nextInt();}
     
    	}
    
    
    
    }
    
    	static double roll(int myDice, int diceInt){
    	int result;
    	if (cash>bet){
    	Random myDice= new Random();
    int randomInt=(int) (Math.random()*6 + 1);
    System.out.println("First dice: " + randomInt);
    
    int diceInt=(int) (Math.random()*6 + 1);
    System.out.println("Second dice: " + diceInt);	
    	else 
    	System.out.println("not enough cash");
    	}
    
    }}

    this is what im trying to get done specifically
    //roll dice
    //compare to see if it is even
    //if even show winning text and add money to cash
    //if not even show losing text and take off.50
    and also i dont know where to put it in the program .. can i get someone to help please? this program is due tomorrow so any help would be appreciated!
    Last edited by Aziombi; 02-13-2013 at 03:03 PM. Reason: adding [code] [/code]

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: okay so i need a little help with my program.

    Hi Aziombi,

    Please disregard.

    Regards.
    Last edited by Ronin; 02-13-2013 at 03:05 PM.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: okay so i need a little help with my program.

    Please post your code inside [code] tags [/code] to retain formatting.
    Please do not ask for code as refusal often offends.

  4. #4
    Aziombi is offline Member
    Join Date
    Feb 2013
    Posts
    5
    Rep Power
    0

    Default Re: okay so i need a little help with my program.

    thanks for the tips. Its not due till 2/24 sorry about that. but i still need to work on it more, im going to be out of class because i broke my ankel

  5. #5
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: okay so i need a little help with my program.

    There are a number of different ways you could complete this assignment and I don't think at this stage your tutor is going to bite your head off if you choose one way over another. As long as you can explain your choices.

    I don't know why you are passing the two ints into the roll method but I'm sure there is a reason. Instead you could pass the choice made by the user regarding the outcome. This method would then roll the two dice and calculate the result. You already have the dice roll, you have to do is use the modulus operator to determine if it is an odd or even. Doubles are just as easy.

    After calculating the outcome how you want to return the result is up to you. This could be a value based upon the amount bet which may require a second parameter to the method, or the string outcome of the dice roll.

    Regards.

  6. #6
    Aziombi is offline Member
    Join Date
    Feb 2013
    Posts
    5
    Rep Power
    0

    Default Re: okay so i need a little help with my program.

    so how would i pass the choice through the method?

  7. #7
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: okay so i need a little help with my program.

    Aziombi, in your last thread I pointed you to the forum rules. Repeat violations are not funny. In fact, they can lead to a ban.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 4
    Last Post: 11-21-2012, 01:19 PM
  2. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  3. Replies: 13
    Last Post: 03-22-2011, 06:49 AM
  4. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 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
  •