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 10 of 10

Thread: Deal or No Deal game help!

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Deal or No Deal game help!

    package whileLoops;

    import java.util.Scanner;
    import java.util.Random;
    import java.util.StringTokenizer;

    public class DealOrNoDeal {

    public static void Instructions(){
    System.out.println("The game will begin once the user has entered the correct password");
    System.out.println("The user will first enter a phrase, the CPU will create a password base on the phrase given");
    System.out.println("The game will then begin with 26 cases");
    System.out.println("The user will pick one case to keep, then pick 6 cases to open");
    System.out.println("The user will be offered cash to keep or to continue playing");
    System.out.println("If the user plays to the end where only one case is left, she/he will have the decision to keep her/his case or switch");
    System.out.println("The final case he/she opens will be the amount of money she/he wins");
    System.out.println();
    System.out.println();
    System.out.println();
    }
    public static void cases(double moneyvalues[]){
    Random generator = new Random();
    for(int i = 0; i < moneyvalues.length; i++){
    int number = generator.nextInt(moneyvalues.length);
    double randomM = moneyvalues[i];
    moneyvalues[i] = moneyvalues[number];
    moneyvalues[number] = randomM;
    System.out.print(moneyvalues[number] + " ");

    }

    }
    public static double banker(int MONEY){
    double offers;
    Random randomGenerator = new Random();
    offers = randomGenerator.nextInt(50000) + 51234;
    System.out.println(offers);
    return offers;
    }
    public static String Password(String PIN){
    PIN = PIN.replace("a", "c");
    PIN = PIN.replace("e", "9");
    PIN = PIN.replace("i", "8");
    PIN = PIN.replace("o", "2");
    PIN = PIN.replace("u", "5");
    return PIN;
    }

    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    double moneyvalue[]= {0.01, 1 , 5, 10, 25, 50, 75, 100, 200, 300, 400, 500, 750, 1000, 5000, 10000, 25000, 50000, 75000, 100000, 200000, 300000, 400000, 500000, 750000, 1000000};
    double []Case = new double [25];
    int Fakeboard[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,2 0,21,22,23,24,25,26};
    String PIN;
    System.out.println("Please enter a phrase");
    PIN = input.nextLine();
    String password = Password(PIN);
    System.out.println("Your password for the game is " + password);
    System.out.println("Enter the password to continue");
    String answer = input.nextLine();
    if(password.equals (answer)){
    System.out.println("Welcome to deal or no deal!");
    Instructions();
    cases(moneyvalue);
    }
    else
    System.out.println("Get out of here scrub!");
    }

    }

    ..new to forums dont know how to put my code in that java box thingy, but anyways...

    Im a grade 11 high school student and for this semester i have java programming, i am a complete beginner and we just learned everything from loops, if statements, arrays, and strings. For our finals we have to create a game or business application, i chose to do a game called Deal or No deal[ google it up i cant put instructions to game in here for some reason] At the moment i am trying to store all the money values in cases, i have managed to randomize it or shuffle them around, but it repeats some values.
    After i fix that i need to somehow store them in 26 cases, so that when i run the program it will display case 1, 2,3, etc. When the player enters 1, it will say
    "you have chosen case 1, case 1 has 500 dollars contained in" and so on.

    Any help and suggestions/feedback will be greatly appreciated, thank you!


  2. #2
    Junior Member
    Join Date
    Jan 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Deal or No Deal game help!

    bumb

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,721
    My Mood
    Mellow
    Thanks
    172
    Thanked 622 Times in 609 Posts

    Default Re: Deal or No Deal game help!

    Welcome to the forum! Please read this topic to learn how to post code correctly along with other useful info for newcomers.

    You've learned arrays, so why don't you store the 26 values in each element of a 26-element array? Case 1 will be element 0, Case 22 = element 21, etc. Populating the array with 26 unique values is another interesting problem that you didn't ask for help with, but let us know how that's going and if you'd like some tips.

    And the word is "bump."

  4. #4
    Junior Member
    Join Date
    Jan 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Deal or No Deal game help!

    package whileLoops;
     
    import java.util.Arrays;
    import java.util.Random;
    import java.util.Scanner;
    import java.util.ArrayList;
     
    public class testclass {
     
    public static ArrayList listTest = new ArrayList();
    public static void Instructions() {
    System.out
    .println("The game will begin once the user has entered the correct password");
    System.out
    .println("The user will first enter a phrase, the CPU will create a password base on the phrase given");
    System.out.println("The game will then begin with 26 cases");
    System.out
    .println("The user will pick one case to keep, then pick 6 cases to open");
    System.out
    .println("The user will be offered cash to keep or to continue playing");
    System.out
    .println("If the user plays to the end where only one case is left, she/he will have the decision to keep her/his case or switch");
    System.out
    .println("The final case he/she opens will be the amount of money she/he wins");
    System.out.println();
    System.out.println();
    System.out.println();
    }
     
    public static void cases(double moneyvalues[]) {
    Random generator = new Random();
    for (int i = 0; i < moneyvalues.length; i++) {
    int number = generator.nextInt(moneyvalues.length);
    double randomM = moneyvalues[i];
    moneyvalues[i] = moneyvalues[number];
    moneyvalues[number] = randomM;
    }
     
    }
     
    public static double banker(int MONEY) {
    double offers;
    Random randomGenerator = new Random();
    offers = randomGenerator.nextInt(50000) + 51234;
    System.out.println(offers);
    return offers;
    }
     
    public static String Password(String PIN) {
    PIN = PIN.replace("a", "c");
    PIN = PIN.replace("e", "9");
    PIN = PIN.replace("i", "8");
    PIN = PIN.replace("o", "2");
    PIN = PIN.replace("u", "5");
    return PIN;
    }
     
    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    double moneyvalue[] = { 0.01, 1, 5, 10, 25, 50, 75, 100, 200, 300, 400,
    500, 750 };
    double moneyvalue2[] = { 1000, 5000, 10000, 25000, 50000, 75000,
    100000, 200000, 300000, 400000, 500000, 750000, 1000000 };
    String PIN;
    System.out.println("Please enter a phrase");
    PIN = input.nextLine();
    String password = Password(PIN);
    System.out.println("Your password for the game is " + password);
    System.out.println("Enter the password to continue");
    String answer = input.nextLine();
    if (password.equals(answer)) {
    System.out.println("Welcome to deal or no deal!");
    Instructions();
    cases(moneyvalue);
    cases(moneyvalue2);
    // displays the money values
    double[] Fakeboard[] = { moneyvalue };
    for (double[] array : Fakeboard) {
    System.out.println(Arrays.toString(array));
    }
    double[] Fakeboard1[] = { moneyvalue2 };
    for (double[] array : Fakeboard1) {
    System.out.println(Arrays.toString(array));
    }
     
    System.out.println();
    System.out.println();
    listTest.add(0);
    listTest.add(1);
    listTest.add(2);
    listTest.add(3);
    listTest.add(4);
    listTest.add(5);
    listTest.add(6);
    listTest.add(7);
    listTest.add(8);
    listTest.add(9);
    listTest.add(10);
    listTest.add(11);
    listTest.add(12);
    listTest.add(13);
    listTest.add(14);
    listTest.add(15);
    listTest.add(16);
    listTest.add(17);
    listTest.add(18);
    listTest.add(19);
    listTest.add(20);
    listTest.add(21);
    listTest.add(22);
    listTest.add(23);
    listTest.add(24);
    listTest.add(25);
     
    System.out.println(" " + listTest + " ");
    System.out.println("Please choose a case to keep");
    int keep = input.nextInt();
     
    listTest.remove(keep);
     
    System.out.println("You have chosen to keep case " + keep);
     
    System.out.println(" " + listTest + " ");
    for(int i = 0; i < 6; i++){
    System.out.println("Please choose a 6 cases to case");
    int keep1 = input.nextInt();
    // other way to do it
    //System.out.println(moneyvalue[keep1]);
    //listTest.remove(keep1);
    //System.out.println(" " + listTest + " ");
    //System.out.println(moneyvalue2[keep1]);
    //listTest.remove(keep1);
    //System.out.println(" " + listTest + " ");
    ///System.out.println(moneyvalue[keep1]);
    ///listTest.remove(keep1);
    ///System.out.println(" " + listTest + " ");
    ///System.out.println(moneyvalue2[keep1]);
    //listTest.remove(keep1);
    //System.out.println(" " + listTest + " ");
    //System.out.println(moneyvalue[keep1]);
    //listTest.remove(keep1);
    //System.out.println(" " + listTest + " ");
    //System.out.println(moneyvalue2[keep1]);
    //listTest.remove(keep1);
    switch (keep1) {
    case 0:
    System.out.println(moneyvalue[0]);
    break;
    case 1:
    System.out.println(moneyvalue[1]);
    break;
    case 2:
    System.out.println(moneyvalue[2]);
    break;
    case 3:
    System.out.println(moneyvalue[3]);
    break;
    case 4:
    System.out.println(moneyvalue[4]);
    break;
    case 5:
    System.out.println(moneyvalue[5]);
    break;
    case 6:
    System.out.println(moneyvalue[6]);
    break;
    case 7:
    System.out.println(moneyvalue[7]);
    break;
    case 8:
    System.out.println(moneyvalue[8]);
    break;
    case 9:
    System.out.println(moneyvalue[9]);
    break;
    case 10:
    System.out.println(moneyvalue[10]);
    break;
    case 11:
    System.out.println(moneyvalue[11]);
    break;
    case 12:
    System.out.println(moneyvalue[12]);
    break;
    case 13:
    System.out.println(moneyvalue2[0]);
    break;
    case 14:
    System.out.println(moneyvalue2[1]);
    break;
    case 15:
    System.out.println(moneyvalue2[2]);
    break;
    case 16:
    System.out.println(moneyvalue2[3]);
    break;
    case 17:
    System.out.println(moneyvalue2[4]);
    break;
    case 18:
    System.out.println(moneyvalue2[5]);
    break;
    case 19:
    System.out.println(moneyvalue2[6]);
    break;
    case 20:
    System.out.println(moneyvalue2[7]);
    break;
    case 21:
    System.out.println(moneyvalue2[8]);
    break;
    case 22:
    System.out.println(moneyvalue2[9]);
    break;
    case 23:
    System.out.println(moneyvalue2[10]);
    break;
    case 24:
    System.out.println(moneyvalue2[11]);
    break;
    case 25:
    System.out.println(moneyvalue2[12]);
    break;
    }
    listTest.remove(keep1);
    System.out.println(" " + listTest + " ");
    }
     
    } else
    System.out.println("Get out of here scrub!");
    }
     
    }

    Thanks for showing me how to put my code properly!

    I realized that half way i can just remove values in an array for display, so i ended up not doing that but still kept arrays for moneyvalues, but did an arraylist for cases. I can now remove cases and such, however for my switch when i have to enter 6 cases, instead of removing case 1 when i select 1, it removes 2, then let say i pick 4, it removes 6, i pick 7, it removes 10. It goes up by 1, 2, 3, 4, 5 to remove. How do i fix this?

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,721
    My Mood
    Mellow
    Thanks
    172
    Thanked 622 Times in 609 Posts

    Default Re: Deal or No Deal game help!

    This bit of code:
    listTest.add(0);
    listTest.add(1);
    listTest.add(2);
    listTest.add(3);
    listTest.add(4);
    // etc . . .
    begs for a loop. You say you've learned these things, but knowing when to apply what you've learned demonstrates that you've really learned the topic. Whenever you find yourself typing something over and over again, you must think, "There has to be a better way . . ." About that time you should think "Loop!", or "Method!" as the better way.

    I didn't look at your code beyond that, but I think I understand your problem. You want to remove items from the collection by its original index, but as soon as you start removing items, the original indices don't apply any more.

    A possible solution would be rather than removing the item at the chosen index, set the value of chosen 'cases' to something that indicates the case is no longer in play, a negative value for instance. Another approach might be to keep a collection of case indices that have not yet been chosen, removing each index as it's chosen. Ultimately, you'd want to create a Case class and include a boolean attribute flag like 'available' or 'chosen' so that a quick check of a Case instance could determine if it could be chosen. I'm not sure you've learned about using classes this way yet, but keep it in mind.

  6. #6
    Junior Member
    Join Date
    Jan 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Deal or No Deal game help!

    Quote Originally Posted by GregBrannon View Post
    This bit of code:
    listTest.add(0);
    listTest.add(1);
    listTest.add(2);
    listTest.add(3);
    listTest.add(4);
    // etc . . .
    begs for a loop. You say you've learned these things, but knowing when to apply what you've learned demonstrates that you've really learned the topic. Whenever you find yourself typing something over and over again, you must think, "There has to be a better way . . ." About that time you should think "Loop!", or "Method!" as the better way.

    I didn't look at your code beyond that, but I think I understand your problem. You want to remove items from the collection by its original index, but as soon as you start removing items, the original indices don't apply any more.

    A possible solution would be rather than removing the item at the chosen index, set the value of chosen 'cases' to something that indicates the case is no longer in play, a negative value for instance. Another approach might be to keep a collection of case indices that have not yet been chosen, removing each index as it's chosen. Ultimately, you'd want to create a Case class and include a boolean attribute flag like 'available' or 'chosen' so that a quick check of a Case instance could determine if it could be chosen. I'm not sure you've learned about using classes this way yet, but keep it in mind.
    I was considering doing a loop or method, it made sense to not have a chunk of code in main, but i havent learned arraylist yet, i just picked it up last night on the web, as for putting it in a method im not sure if its done as the same as others but ill definitely give it a try now. For the possible solutions did u mean to like replace the chosen case with a another name? Such as, if ichose 1, instead of removing it, i would replace it with the letter G.

  7. #7
    Junior Member
    Join Date
    Jan 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Deal or No Deal game help!

    package whileLoops;
     
    import java.util.Arrays;
    import java.util.Random;
    import java.util.Scanner;
    import java.util.ArrayList;
     
    public class testclass {
     
    	// stores the money values and allows me to use it anywhere
    	static 	double moneyvalue[] = { 0.01, 1, 5, 10, 25, 50, 75, 100, 200, 300, 400, 
    		500, 750 };
    	static double moneyvalue2[] = { 1000, 5000, 10000, 25000, 50000, 75000,
    		100000, 200000, 300000, 400000, 500000, 750000, 1000000 };
     
    	//allows me to use arraylist
    	public static ArrayList listTest = new ArrayList();
     
     
    	// creates the cases from 0 - 25 to display
    	public static void fakeboard(){
    		listTest.add(0);
    		listTest.add(1); 
    		listTest.add(2);
    		listTest.add(3);
    		listTest.add(4);
    		listTest.add(5);
    		listTest.add(6);
    		listTest.add(7);
    		listTest.add(8);
    		listTest.add(9);
    		listTest.add(10);
    		listTest.add(11);
    		listTest.add(12);
    		listTest.add(13);
    		listTest.add(14);
    		listTest.add(15);
    		listTest.add(16);
    		listTest.add(17);
    		listTest.add(18);
    		listTest.add(19);
    		listTest.add(20);
    		listTest.add(21);
    		listTest.add(22);
    		listTest.add(23);
    		listTest.add(24);
    		listTest.add(25);
    	}
    	//outputs the instructions
    	public static void Instructions() {
    		System.out.println("The game will begin once the user has entered the correct password");
    		System.out.println("The user will first enter a phrase, the CPU will create a password base on the phrase given");
    		System.out.println("The game will then begin with 0-25 cases");
    		System.out.println("The user will pick one case to keep, then pick 6 cases to open");
    		System.out.println("The user will be offered cash to keep or to continue playing");
    		System.out.println("If the user plays to the end where only one case is left, she/he will have the decision to keep her/his case or switch");
    		System.out.println("The final case he/she opens will be the amount of money she/he wins");
    		System.out.println("Note: The letter G means that the case has already been picked");
     
    		System.out.println();
    		System.out.println();
    		System.out.println();
    	}
    	// randomizes the money values so that it wont be in the same spot every time a new game is started
    	public static void cases(double moneyvalues[]) {
    		Random generator = new Random();
    		for (int i = 0; i < moneyvalues.length; i++) {
    			int number = generator.nextInt(moneyvalues.length);
    			double randomM = moneyvalues[i];
    			moneyvalues[i] = moneyvalues[number];
    			moneyvalues[number] = randomM;
    		}
     
    	}
    	//allows the user to enter 4 cases, but a different offer is given from the banker 
    	public static void banker() {
    		double offers;
    		int variable = 4;
    		Scanner input = new Scanner(System.in);
    		Random randomGenerator = new Random();
    		offers = randomGenerator.nextInt(10000) + 51234;
    		System.out.println("The banker has offered you " + offers + " dollars!");
     
    		System.out.println("Deal or No deal? 1. Deal 2. No Deal");
    		int deal = input.nextInt();
     
    		if(deal == 1){
    			System.out.println("Congratulations, you have won " + offers + " dollars!");
    		}
    		else
     
    			for(int i = 0; i < 4; i++){
     
    				System.out.println("Please choose " + variable +" case.");
    				int keep1 = input.nextInt();
     
    				choose(keep1);
     
    				listTest.set(keep1 - 1, " ");
    				System.out.println(" " + listTest + " ");
    				variable--;
    				}
     
    	}
     
    	public static void banker1(){
    		double offers;
    		int variable = 4;
    		Scanner input = new Scanner(System.in);
    		Random randomGenerator = new Random();
    		offers = randomGenerator.nextInt(20000) + 51234;
    		System.out.println("The banker has offered you " + offers + " dollars!");
     
    		System.out.println("Deal or No deal? 1. Deal 2. No Deal");
    		int deal = input.nextInt();
     
    		if(deal == 1){
    			System.out.println("Congratulations, you have won " + offers + " dollars!");
    		}
    		else
     
    			for(int i = 0; i < 4; i++){
     
    				System.out.println("Please choose " + variable +" case.");
    				int keep1 = input.nextInt();
     
    				choose(keep1);
     
    				listTest.set(keep1 - 1, " ");
    				System.out.println(" " + listTest + " ");
    				variable--;
    				}
     
    	}
    	public static void banker2(){
    		double offers;
    		int variable = 4;
    		Scanner input = new Scanner(System.in);
    		Random randomGenerator = new Random();
    		offers = randomGenerator.nextInt(30000) + 51234;
    		System.out.println("The banker has offered you " + offers + " dollars!");
     
    		System.out.println("Deal or No deal? 1. Deal 2. No Deal");
    		int deal = input.nextInt();
     
    		if(deal == 1){
    			System.out.println("Congratulations, you have won " + offers + " dollars!");
    		}
    		else
     
    			for(int i = 0; i < 4; i++){
     
    				System.out.println("Please choose " + variable +" case.");
    				int keep1 = input.nextInt();
     
    				choose(keep1);
     
    				listTest.set(keep1 - 1, " ");
    				System.out.println(" " + listTest + " ");
    				variable--;
    				}
     
    	}
    	public static void banker3(){
    		double offers;
    		int variable = 4;
    		Scanner input = new Scanner(System.in);
    		Random randomGenerator = new Random();
    		offers = randomGenerator.nextInt(40000) + 51234;
    		System.out.println("The banker has offered you " + offers + " dollars!");
     
    		System.out.println("Deal or No deal? 1. Deal 2. No Deal");
    		int deal = input.nextInt();
     
    		if(deal == 1){
    			System.out.println("Congratulations, you have won " + offers + " dollars!");
    		}
    		else
     
    			for(int i = 0; i < 4; i++){
     
    				System.out.println("Please choose " + variable +" case.");
    				int keep1 = input.nextInt();
     
    				choose(keep1);
     
    				listTest.set(keep1 - 1, " ");
    				System.out.println(" " + listTest + " ");
    				variable--;
    				}
     
    	}
    	public static void banker4(){
    		double offers;
    		int variable = 2;
    		Scanner input = new Scanner(System.in);
    		Random randomGenerator = new Random();
    		offers = randomGenerator.nextInt(50000) + 51234;
    		System.out.println("The banker has offered you " + offers + " dollars!");
     
    		System.out.println("Deal or No deal? 1. Deal 2. No Deal");
    		int deal = input.nextInt();
     
    		if(deal == 1){
    			System.out.println("Congratulations, you have won " + offers + " dollars!");
    		}
    		else
     
    			for(int i = 0; i < 2; i++){
     
    				System.out.println("Please choose " + variable +" case.");
    				int keep1 = input.nextInt();
     
    				choose(keep1);
     
    				listTest.set(keep1 - 1, " ");
    				System.out.println(" " + listTest + " ");
    				variable--;
    				}
     
    	}
    	//method for when 2 cases are left,outputs the money they won in a formated way
    	public static void choosefinal(int keep1){
    	switch (keep1) {
    	case 0:
    		System.out.println("Congratulations you have won " + moneyvalue[0] + " dollars!");
    		System.out.println();
    		break;
    	case 1:
    		System.out.println("Congratulations you have won " + moneyvalue[1] + " dollars!");
    		System.out.println();
    		break;
    	case 2:
    		System.out.println("Congratulations you have won " + moneyvalue[2] + " dollars!");
    		System.out.println();
    		break;
    	case 3:
    		System.out.println("Congratulations you have won " + moneyvalue[3] + " dollars!");
    		System.out.println();
    		break;
    	case 4:
    		System.out.println( "Congratulations you have won " + moneyvalue[4] + " dollars!");
    		System.out.println();
    		break;
    	case 5:
    		System.out.println("Congratulations you have won " + moneyvalue[5] + " dollars!");
    		System.out.println();
    		break;
    	case 6:
    		System.out.println("Congratulations you have won " + moneyvalue[6] + " dollars!");
    		System.out.println();
    		break;
    	case 7:
    		System.out.println( "Congratulations you have won " + moneyvalue[7] + " dollars!");
    		System.out.println();
    		break;
    	case 8:
    		System.out.println( "Congratulations you have won " + moneyvalue[8] + " dollars!");
    		System.out.println();
    		break;
    	case 9:
    		System.out.println( "Congratulations you have won " + moneyvalue[9] + " dollars!");
    		System.out.println();
    		break;
    	case 10:
    		System.out.println( "Congratulations you have won " + moneyvalue[10] + " dollars!");
    		System.out.println();
    		break;
    	case 11:
    		System.out.println( "Congratulations you have won " + moneyvalue[11] + " dollars!");
    		System.out.println();
    		break;
    	case 12:
    		System.out.println( "Congratulations you have won " + moneyvalue[12] + " dollars!");
    		System.out.println();
    		break;
    	case 13:
    		System.out.println( "Congratulations you have won " + moneyvalue2[0] + " dollars!");
    		System.out.println();
    		break;
    	case 14:
    		System.out.println( "Congratulations you have won " + moneyvalue2[1] + " dollars!");
    		System.out.println();
    		break;
    	case 15:
    		System.out.println( "Congratulations you have won " + moneyvalue2[2] + " dollars!");
    		System.out.println();
    		break;
    	case 16:
    		System.out.println( "Congratulations you have won " + moneyvalue2[3] + " dollars!");
    		System.out.println();
    		break;
    	case 17:
    		System.out.println( "Congratulations you have won " + moneyvalue2[4] + " dollars!");
    		System.out.println();
    		break;
    	case 18:
    		System.out.println( "Congratulations you have won " + moneyvalue2[5] + " dollars!");
    		System.out.println();
    		break;
    	case 19:
    		System.out.println( "Congratulations you have won " + moneyvalue2[6] + " dollars!");
    		System.out.println();
    		break;
    	case 20:
    		System.out.println( "Congratulations you have won " + moneyvalue2[7] + " dollars!");
    		System.out.println();
    		break;
    	case 21:
    		System.out.println( "Congratulations you have won " + moneyvalue2[8] + " dollars!");
    		System.out.println();
    		break;
    	case 22:
    		System.out.println( "Congratulations you have won " + moneyvalue2[9] + " dollars!");
    		System.out.println();
    		break;
    	case 23:
    		System.out.println( "Congratulations you have won " + moneyvalue2[10] + " dollars!");
    		System.out.println();
    		break;
    	case 24:
    		System.out.println( "Congratulations you have won " + moneyvalue2[11] + " dollars!");
    		System.out.println();
    		break;
    	case 25:
    		System.out.println( "Congratulations you have won " + moneyvalue2[12] + " dollars!");
    		System.out.println();
    		break;
    	 default:
    	  System.out.println("inappropriate number, please try again.");
    	   break;
     
    	}
    	}
    	// gives the user the option to switch 
    	// or keep its current case
    	// it will then output the money in the case which is the money they will win
    	public static void finalcase(){
    		Scanner input = new Scanner(System.in);
    		System.out.println("There is only one case left");
    		System.out.println("Would you like to keep your case or switch it?");
     
    		System.out.println("Press 1 to switch, 2 to keep current case");
    		int deal = input.nextInt();
     
     
     
    		for(int i = 0; i < 1; i++ )
    		if(deal == 1){
    			System.out.println("Enter the switched case, case number");
    			int finalchoose = input.nextInt();
    			choosefinal(finalchoose);
    			System.out.println("Thanks for playing!");
    		}
    		else
    		System.out.println("Enter your case number");
    		int finalchoose = input.nextInt();    
    		choosefinal(finalchoose);
    		System.out.println("Thanks for playing!");
     
     
     
     
     
    	}
    	// accepts a phrase from the user and replaces the vowels with 
    	// other values/letters to create a new password for the user
    	// to enter with to play the game
    	public static String Password(String PIN) {
    		PIN = PIN.replace("a", "c");
    		PIN = PIN.replace("e", "9");
    		PIN = PIN.replace("i", "8");
    		PIN = PIN.replace("o", "2");
    		PIN = PIN.replace("u", "5");
    		return PIN;
    	}
     
    	// stores the money values/ displays them in a formatted way
    	// also allows the user to choose an option
    	public static void choose(int keep1){
    		switch (keep1) {
    		case 0:
    			System.out.println("Case 0: " + moneyvalue[0]);
    			System.out.println();
    			break;
    		case 1:
    			System.out.println("Case 1: " + moneyvalue[1]);
    			System.out.println();
    			break;
    		case 2:
    			System.out.println("Case 2: " + moneyvalue[2]);
    			System.out.println();
    			break;
    		case 3:
    			System.out.println("Case 3: " + moneyvalue[3]);
    			System.out.println();
    			break;
    		case 4:
    			System.out.println("Case 4: " + moneyvalue[4]);
    			System.out.println();
    			break;
    		case 5:
    			System.out.println("Case 5: " + moneyvalue[5]);
    			System.out.println();
    			break;
    		case 6:
    			System.out.println("Case 6: " + moneyvalue[6]);
    			System.out.println();
    			break;
    		case 7:
    			System.out.println("Case 7: " + moneyvalue[7]);
    			System.out.println();
    			break;
    		case 8:
    			System.out.println("Case 8: " + moneyvalue[8]);
    			System.out.println();
    			break;
    		case 9:
    			System.out.println("Case 9: " + moneyvalue[9]);
    			System.out.println();
    			break;
    		case 10:
    			System.out.println("Case 10: " + moneyvalue[10]);
    			System.out.println();
    			break;
    		case 11:
    			System.out.println("Case 11: " + moneyvalue[11]);
    			System.out.println();
    			break;
    		case 12:
    			System.out.println("Case 12: " + moneyvalue[12]);
    			System.out.println();
    			break;
    		case 13:
    			System.out.println("Case 13: " + moneyvalue2[0]);
    			System.out.println();
    			break;
    		case 14:
    			System.out.println("Case 14: " + moneyvalue2[1]);
    			System.out.println();
    			break;
    		case 15:
    			System.out.println("Case 15: " + moneyvalue2[2]);
    			System.out.println();
    			break;
    		case 16:
    			System.out.println("Case 16: " + moneyvalue2[3]);
    			System.out.println();
    			break;
    		case 17:
    			System.out.println("Case 17: " + moneyvalue2[4]);
    			System.out.println();
    			break;
    		case 18:
    			System.out.println("Case 18: " + moneyvalue2[5]);
    			System.out.println();
    			break;
    		case 19:
    			System.out.println("Case 19: " + moneyvalue2[6]);
    			System.out.println();
    			break;
    		case 20:
    			System.out.println("Case 20: " + moneyvalue2[7]);
    			System.out.println();
    			break;
    		case 21:
    			System.out.println("Case 21: " + moneyvalue2[8]);
    			System.out.println();
    			break;
    		case 22:
    			System.out.println("Case 22: " + moneyvalue2[9]);
    			System.out.println();
    			break;
    		case 23:
    			System.out.println("Case 23: " + moneyvalue2[10]);
    			System.out.println();
    			break;
    		case 24:
    			System.out.println("Case 24: " + moneyvalue2[11]);
    			System.out.println();
    			break;
    		case 25:
    			System.out.println("Case 25: " + moneyvalue2[12]);
    			System.out.println();
    			break;
    		 default:
    		  System.out.println("inappropriate number, please try again.");
    		   break;
     
    		}
     
    	}
     
    	public static void main(String[] args) {
    		Scanner input = new Scanner(System.in);
    		String PIN;
    		System.out.println("Please enter a phrase");
    		PIN = input.nextLine();
    		String password = Password(PIN);
    		System.out.println("Your password for the game is " + password);
    		System.out.println("Enter the password to continue");
    		String answer = input.nextLine();
    		// if password is equal to the new given password
    		// the game will proceed, otherwise output statement
    		if (password.equals(answer)) {
    			System.out.println("Welcome to deal or no deal!");
    			Instructions(); // calls the instructions
    			cases(moneyvalue); // calls the randomized money values
    			cases(moneyvalue2); // calls the second randomized money values
     
    			// displays the money values
    			double[] Fakeboard[] = { moneyvalue };
    			for (double[] array : Fakeboard) {
    				System.out.println(Arrays.toString(array));
    			}
    			double[] Fakeboard1[] = { moneyvalue2 };
    			for (double[] array : Fakeboard1) {
    				System.out.println(Arrays.toString(array));
    			}
     
    			System.out.println();
    			System.out.println();
     
    			fakeboard(); // calls the case to be displayed
     
    			System.out.println(" " + listTest + " "); // outputs current case list
     
    			System.out.println("Please choose a case to keep");
    			int keep = input.nextInt();
     
    			listTest.remove(keep); // removes the case the user just selected to keep from the array
     
    			System.out.println("You have chosen to keep case " + keep);
     
    			System.out.println(" " + listTest + " "); // outputs new current case list
     
    			int variable = 6;
    			// allows user to choose 6 cases
    			for(int i = 0; i < 6; i++){
     
    				System.out.println("Please choose " + variable +" cases.");
    				int keep1 = input.nextInt();
     
    				choose(keep1);
     
     
    				listTest.set(keep1 - 1, " "); // replaces the chosen case with a space to indicate to user its been chosen already
    				System.out.println(" " + listTest + " ");
    				variable--;
    				}
     
    			System.out.println("");
     
    			banker(); 
    			banker1();
    			banker2();
    			banker3();
    			banker4();
    			finalcase();
     
     
    		} else
    			System.out.println("Wrong password! Access denied!");
    	}
     
    }

    Just finished making the game, a lot of little things needed to be done to make it more user friendly, but super rough atm
    It runs fine and everything, except when i choose case 25 to keep first.
    Other then that any suggestions on what i should do to make it even more efficient/better?

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,721
    My Mood
    Mellow
    Thanks
    172
    Thanked 622 Times in 609 Posts

    Default Re: Deal or No Deal game help!

    I've made some observations and suggestions, but I don't know that you need to worry about any of them for this project. Incorporating some of my suggestions requires a major change to your program architecture and may be more than you're ready for. Other suggestions are simple, practically no impact. I think this is an excellent effort for an 11th grader with a semester of programming who has "just learned everything from loops, if statements, arrays, and strings." I don't know what your instructor expects, but I think what you've posted should wow 'em. Good job!

    If you do make changes to what you've posted, practice simple version control. Always save the last working version so you'll have that to fall back on. Then, if you make so many changes that you end up with a pile of code that doesn't work, fall back to the last working version as a starting point. Don't lose that last working version, never modify it directly, always do a "save as" and start from a copy.

    My comments/observations:

    By convention in Java, class names begin with capital letters, camel-cased thereafter. Method and variable names begin with lowercase letters and are then camel-cased.

    A loop to fill the ArrayList:
    for ( int i = 0 ; i < 26 ; i++ )
    {
        listTest.add( i );
    }
    Isn't that simpler?

    For readability, it is common practice to keep source code line lengths to less than 80 columns. With today's modern monitors, perhaps this number can be increased, especially to a number suitable in one's own environment, but for sharing with others and posting on the web it's still a good number.

    I really like your use of methods (uncommon at your stage) and that you occasionally added simple and appropriate comments that describe the purpose of major program elements (also uncommon, but at any stage). Please make adding comments a consistent practice.

    The next step in your use of methods is to get rid of static methods entirely, except for main() of course. That is accomplished by not 'driving' the program from the main() method. The main method should be a few lines that simply begin the program. The simplest main() method is a single line that calls the constructor of another class. Another approach is to use main() to create an instance of another classes and then kickoff the program using that instance.

    The approach I described above (non static methods) will allow you to simplify your code in several ways. Many of your methods do more than they should and have more local variables and objects than they should. One Scanner and one Random object should serve the whole program. A method should do one thing - exactly what its name says it will do - it should do it very well, and it should do nothing else.

    The switch() statements in methods choose() and choosefinal() (should be named chooseFinal()) can be simplified significantly, and a switch() statement may not be the best design. Again, programming tools were invented to take advantage of repetitive tasks. You're good at reducing a problem to a repetitive result, now simplify the programming of that result to a few lines. (Someone I respect contends that switch() statements should only be used by the lazy and unimaginative, but that might be a bit harsh.)

    The existing main() method will be improved by incorporating the other suggestions I've made.

    Keep coding and don't be a stranger.

  9. #9
    Junior Member
    Join Date
    Jan 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Deal or No Deal game help!

    Thank you so much for your help! I will definitely take those suggestions and see what i can do with them.

  10. #10
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,721
    My Mood
    Mellow
    Thanks
    172
    Thanked 622 Times in 609 Posts

    Default Re: Deal or No Deal game help!

    You're welcome.

Similar Threads

  1. About layering JFrames JPanels and the whole deal with that?
    By .Swing in forum Java Theory & Questions
    Replies: 4
    Last Post: June 9th, 2012, 12:27 PM
  2. Not a big deal - Make me a GUI!
    By flashzero in forum Paid Java Projects
    Replies: 1
    Last Post: January 26th, 2012, 01:00 PM
  3. Not sure how to deal with addActionListener! :3
    By Asteroid555 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 1st, 2011, 01:57 PM
  4. No Time To Deal With The Assigment
    By Vins25 in forum Java Theory & Questions
    Replies: 14
    Last Post: May 3rd, 2011, 07:39 AM