Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Deal or No Deal

  1. #1
    New to the CF scene
    Join Date
    May 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Deal or No Deal

    Ive accidently posted this in JavaScript section

    But anyway,

    I am taking Java in high school as my graduation requirement. And as our final project we are to make Deal or no Deal game on JCreator.

    Now the most recent topic we covered was ArrayLists, we also covered topics like for/while loops, Exceptions and etc...

    i have so far been able to print the money values and cases. So yea i got something started, i got some help from some of my classmates.
    I really really need some major help. I am a complete beginner and not a computer guy so this class was always a challenge to me (for me tougher than Calc 3, haha)

    so if anyone anyone at all can help me please please let me know so I can show you what i have so far. This is some really basic Java compared to what you guys do here. like first year high school java (so i was really hoping to see some light at the end of the tunnel by coming here).

    Heres my Code so far:

    Code:
    import java.lang.Math;
    import java.io.*;
    import java.util.*;
    
    public class DealOrNoDeal
    {
    	Scanner in = new Scanner(System.in);
    	Scanner inFile;
    	
    	private ArrayList <Double> money = new ArrayList <Double> (26);
    	private ArrayList <Double> moneyMix = new ArrayList <Double> (26);
    	private int myCase;
    	private double myCaseValue;
    	private int myRound = 1;
    	private int casesLeft = 6;
    
    	//stores money into cases randomly
    	public void setCases()
    	{
    		ArrayList <Double> temp = new ArrayList <Double> (money);
    		
    		while (temp.size() != 0)
    		{
    			moneyMix.add(temp.remove((int)(Math.random()*temp.size())));
    		}
    	}
    	
    	//gets money from file
    	public void getMoney()
    	{
    		try{
    			inFile = new Scanner(new File("dealmoney.txt"));
    		}catch(IOException i){
    			System.out.println("Error: "+ i.getMessage());
    		}
    		
    		while (inFile.hasNext())
    		{
    			money.add(inFile.nextDouble());
    		}
    		
    		/*for(int x=1; x<=26; x++)
    			System.out.print(money.get(x) + " ");*/
    	}
    	
    	//asks user to pick case to keep
    	public void keepCase()
    	{
    		System.out.print("Keep case #: ");
    		myCase = in.nextInt();
    		myCaseValue = moneyMix.get(myCase - 1);
    		moneyMix.set(myCase-1,0.0);
    	}
    	
    	//ask user case# choice
    	public void chooseCase()
    	{
    		System.out.println("Round " + myRound);
    		System.out.print(casesLeft + " cases left - ");
    		int  chooseCase = in.nextInt();
    		moneyMix.set(chooseCase-1,0.0);
    	}
    	
    	//displays cases
    	public void displayCases()
    	{
    		for(int x=1; x<=26; x++)
    		{
    			if(money.get(x-1) != 0)
    				System.out.print(x + " ");
    			else 
    				System.out.print("X ");
    		}
    		System.out.println();
    	}
    	
    	//displays money
    	public void displayMoney()
    	{
    		for(int x=1; x<=26; x++)
    		{
    			if(money.get(x-1) != 0)
    				System.out.print("$" + money.get(x-1) + " ");
    			else 
    				System.out.print("X ");
    		}
    		System.out.println();
    		System.out.println();
    	}
    	
    	//plays game
    	public void play()
    	{
    		getMoney();
    		setCases();
    		displayCases();
    		displayMoney();
    		keepCase();
    		chooseCase();
    		
    	}
    	
    	//runs program
    	public static void main(String[] args)
    	{
    		DealOrNoDeal game = new DealOrNoDeal();
    		game.play();
    	}
    }


    Please PM me or e-mail me at : viseshv@gmail.com

    hope we can work together
    Last edited by TheLstSpartan; 05-26-2008 at 06:14 AM.

  • #2
    Regular Coder Aradon's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    734
    Thanks
    0
    Thanked 20 Times in 19 Posts
    You need to please describe the problem you are having. We aren't going to do your homework for you but we will help you.
    "To iterate is human, to recurse divine." -L. Peter Deutsch

  • #3
    New to the CF scene
    Join Date
    May 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Aradon View Post
    You need to please describe the problem you are having. We aren't going to do your homework for you but we will help you.
    sorry i havent had time to get back and couldnt really describe my problem:

    But the problem im having right now is i am at the part where the player has to start playing the actual game. Like round 1 picks 6 cases and then the banker makes a deal and the round 2 pick 5 cases and then the bankers makes another offer. This goes on up to round 9 and the last couple of rounds the player picks like 1 case. (I dont know if you know how the game works so excuse my lengthy explanation)

    I know that i have to make a banker method that makes an offer at the end of each round.
    And make a "chooser" method that pretty much lets the player pick cases.

    Well this is what i came up with for the player to pick the cases: I am overwhelmed by a lot of errors right now that im trying to dig up so i dont exactly know if it works. IF you can look over it and let me know what you think thatd be great.

    Code:
    public void chooser()
    	{
    		System.out.println("Pick your next case!");
    		howiesScanner = new Scanner(System.in);
    		int temp = howiesScanner.nextInt();
    		//if its been pickd, make it null
    		if(randomValues.get(temp)!=null)
    		{
    			System.out.println("You have revealed case number " + 
    			temp +". It's value is " + randomValues.get(temp));
    			randomValues.set(temp,null);
    		}
    		else
    		{
    			//when the player picks the same case
    			System.out.println("You already picked that case, smarts. Pick a new one!");
    			chooser();
    		}
    		
    	}
    This is due for me on Monday so I dont have a lot of time but then again if this works and if my banker method works im pretty much done, I just have to fix some errors.

  • #4
    Regular Coder
    Join Date
    Apr 2008
    Posts
    685
    Thanks
    15
    Thanked 105 Times in 104 Posts
    I'm not too good with Java, I just know some basics, but this is maybe how you could go about it.

    You have the 26 boxes and their values inside an ArrayList
    You have the rounds, and boxes to be opened inside a round inside another ArrayList

    So when the user starts the game, and they input the value you need to possibly do something like this:

    for (Values v : money) {
    if (userValue == v.getBoxValue) {
    /*This Box Has Been Picked So:*/
    Output the Value to the User
    Set the Box to a Null Value
    ++ The Counter for the Boxes Selected
    -- boxesRemaining
    Then Check the Counter against the amount of boxes allowed in this round
    If counter==allowedBoxes then ++roundCounter and run the banker metho

    The Banker could calculate an offer like:

    int offerTotal;
    for (values V : otherName) {
    offerTotal += v.getBoxValue
    }
    double bankerOffer = offerTotal / boxesRemaining

    This would give an average offer, you could also implement the use of the random library to mix it up a little bit (i.e assign an importance to a box, so if there is 5 boxes of little importance the offer is lower than the average, and if there are 2 important boxes add onto the average). You also need to add validation to check user input values are possible.
    Last edited by Scriptet; 05-30-2008 at 08:02 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
    •