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!");
}
}