package magicStackResources; import stacksFromClassBook.*; import java.util.Scanner; public class Trick { int magicStackDeckSize = 21; int collumnSize = 7; int betBait = 13; StackInterface leftCollumn = new ArrayStack<>(collumnSize); StackInterface middleCollumn = new ArrayStack<>(collumnSize); StackInterface rightCollumn = new ArrayStack<>(collumnSize); StackInterface excess = new ArrayStack<>(magicStackDeckSize); public boolean theTrick(String element[]) { boolean advance = true; boolean won; int counter; int leftCounter = 0; int middleCounter = 7; int rightCounter = 14; String userInput; String[] topElement = new String[1]; String[] magicStackDeck = new String[magicStackDeckSize]; Scanner input = new Scanner(System.in); for(counter = 0; counter < magicStackDeckSize; counter++) excess.push(element[counter]); counter = 0; while(!excess.isEmpty()) { topElement[0] = excess.top(); if(counter < 7) leftCollumn.push(topElement[0]); else if(counter >= 7 && counter < 14) middleCollumn.push(topElement[0]); else if(counter >= 14) rightCollumn.push(topElement[0]); excess.pop(); counter++; } while(leftCounter < 7) { System.out.print(element[rightCounter] + "\t"); System.out.print(element[middleCounter] + "\t"); System.out.print(element[leftCounter] + "\t" + "\n"); leftCounter++; middleCounter++; rightCounter++; } System.out.print("Mentally pick one of the above cards. Now, which stack is your card in? (Please enter L for Left, M for Middle, or R for Right.): "); userInput = input.nextLine(); while(advance != true) { if(userInput.equalsIgnoreCase("L")) { for(counter = 0; counter < 7; counter++) { topElement[0] = middleCollumn.top(); excess.push(topElement[0]); middleCollumn.pop(); } for(counter = 0; counter < 7; counter++) { topElement[0] = rightCollumn.top(); middleCollumn.push(topElement[0]); rightCollumn.pop(); } for(counter = 0; counter < 7; counter++) { topElement[0] = excess.top(); rightCollumn.push(topElement[0]); excess.pop(); } advance = true; } else if(userInput.equalsIgnoreCase("M")) { advance = true; } else if(userInput.equalsIgnoreCase("R")) { for(counter = 0; counter < 7; counter++) { topElement[0] = middleCollumn.top(); excess.push(topElement[0]); middleCollumn.pop(); } for(counter = 0; counter < 7; counter++) { topElement[0] = leftCollumn.top(); middleCollumn.push(topElement[0]); leftCollumn.pop(); } for(counter = 0; counter < 7; counter++) { topElement[0] = excess.top(); leftCollumn.push(topElement[0]); excess.pop(); } advance = true; } else { System.out.print("You did not enter a valid response. Please enter L for Left, M for Middle, or R for Right.: "); userInput = input.nextLine(); advance = false; } } counter = 0; while(counter < magicStackDeckSize) { if(counter < 7) { topElement[0] = rightCollumn.top(); excess.push(topElement[0]); rightCollumn.pop(); } else if(counter >= 7 && counter < 14) { topElement[0] = middleCollumn.top(); excess.push(topElement[0]); middleCollumn.pop(); } else if(counter >= 14) { topElement[0] = leftCollumn.top(); excess.push(topElement[0]); leftCollumn.pop(); } counter++; } counter = magicStackDeckSize - 1; while(!excess.isEmpty()) { topElement[0] = excess.top(); magicStackDeck[counter] = topElement[0]; leftCollumn.push(topElement[0]); excess.pop(); counter--; topElement[0] = excess.top(); magicStackDeck[counter] = topElement[0]; middleCollumn.push(topElement[0]); excess.pop(); counter--; topElement[0] = excess.top(); magicStackDeck[counter] = topElement[0]; rightCollumn.push(topElement[0]); excess.pop(); counter--; } counter = 0; while(counter < magicStackDeckSize) { System.out.print(element[counter] + "\t"); counter++; System.out.print(element[counter] + "\t"); counter++; System.out.print(element[counter] + "\n"); counter++; } System.out.print("Now, which stack is your card in? (Please enter L for Left, M for Middle, or R for Right.): "); userInput = input.nextLine(); while(advance != true) { if(userInput.equalsIgnoreCase("R")) { for(counter = 0; counter < 7; counter++) { topElement[0] = middleCollumn.top(); excess.push(topElement[0]); middleCollumn.pop(); } for(counter = 0; counter < 7; counter++) { topElement[0] = rightCollumn.top(); middleCollumn.push(topElement[0]); rightCollumn.pop(); } for(counter = 0; counter < 7; counter++) { topElement[0] = excess.top(); rightCollumn.push(topElement[0]); excess.pop(); } advance = true; } else if(userInput.equalsIgnoreCase("M")) { advance = true; } else if(userInput.equalsIgnoreCase("L")) { for(counter = 0; counter < 7; counter++) { topElement[0] = middleCollumn.top(); excess.push(topElement[0]); middleCollumn.pop(); } for(counter = 0; counter < 7; counter++) { topElement[0] = leftCollumn.top(); middleCollumn.push(topElement[0]); leftCollumn.pop(); } for(counter = 0; counter < 7; counter++) { topElement[0] = excess.top(); leftCollumn.push(topElement[0]); excess.pop(); } advance = true; } else { System.out.print("You did not enter a valid response. Please enter L for Left, M for Middle, or R for Right.: "); userInput = input.nextLine(); advance = false; } counter = 0; } while(counter < magicStackDeckSize) { if(counter < 7) { topElement[0] = rightCollumn.top(); excess.push(topElement[0]); rightCollumn.pop(); } else if(counter >= 7 && counter < 14) { topElement[0] = middleCollumn.top(); excess.push(topElement[0]); middleCollumn.pop(); } else if(counter >= 14) { topElement[0] = leftCollumn.top(); excess.push(topElement[0]); leftCollumn.pop(); } counter++; } counter = magicStackDeckSize - 1; while(!excess.isEmpty()) { topElement[0] = excess.top(); magicStackDeck[counter] = topElement[0]; leftCollumn.push(topElement[0]); excess.pop(); counter--; topElement[0] = excess.top(); magicStackDeck[counter] = topElement[0]; middleCollumn.push(topElement[0]); excess.pop(); counter--; topElement[0] = excess.top(); magicStackDeck[counter] = topElement[0]; rightCollumn.push(topElement[0]); excess.pop(); counter--; } counter = 0; leftCounter = 0; middleCounter = 7; rightCounter = 14; while(leftCounter < 7) { System.out.print(element[rightCounter] + "\t"); System.out.print(element[middleCounter] + "\t"); System.out.print(element[leftCounter] + "\t" + "\n"); leftCounter++; middleCounter++; rightCounter++; } System.out.print("Now, which stack is your card in? (Please enter L for Left, M for Middle, or R for Right.): "); userInput = input.nextLine(); while(advance != true) { if(userInput.equalsIgnoreCase("R")) { for(counter = 0; counter < 7; counter++) { topElement[0] = middleCollumn.top(); excess.push(topElement[0]); middleCollumn.pop(); } for(counter = 0; counter < 7; counter++) { topElement[0] = rightCollumn.top(); middleCollumn.push(topElement[0]); rightCollumn.pop(); } for(counter = 0; counter < 7; counter++) { topElement[0] = excess.top(); rightCollumn.push(topElement[0]); excess.pop(); } advance = true; } else if(userInput.equalsIgnoreCase("M")) { advance = true; } else if(userInput.equalsIgnoreCase("L")) { for(counter = 0; counter < 7; counter++) { topElement[0] = middleCollumn.top(); excess.push(topElement[0]); middleCollumn.pop(); } for(counter = 0; counter < 7; counter++) { topElement[0] = leftCollumn.top(); middleCollumn.push(topElement[0]); leftCollumn.pop(); } for(counter = 0; counter < 7; counter++) { topElement[0] = excess.top(); leftCollumn.push(topElement[0]); excess.pop(); } advance = true; } else { System.out.print("You did not enter a valid response. Please enter L for Left, M for Middle, or R for Right.: "); userInput = input.nextLine(); advance = false; } counter = 0; } while(counter < magicStackDeckSize) { if(counter < 7) { topElement[0] = rightCollumn.top(); excess.push(topElement[0]); rightCollumn.pop(); } else if(counter >= 7 && counter < 14) { topElement[0] = middleCollumn.top(); excess.push(topElement[0]); middleCollumn.pop(); } else if(counter >= 14) { topElement[0] = leftCollumn.top(); excess.push(topElement[0]); leftCollumn.pop(); } counter++; } counter = magicStackDeckSize - 1; while(counter >= 0) { magicStackDeck[counter] = excess.top(); excess.pop(); counter--; } for(counter = 0; counter < betBait; counter++) System.out.print(magicStackDeck[counter] + " "); System.out.print("I bet you 50 USD that the next card that is displayed will be your card. Please enter Y for yes if you want to take the bet or anything else if you don't.: "); userInput = input.nextLine(); if(userInput.equalsIgnoreCase("Y")) won = false; else won = true; System.out.println(magicStackDeck[10] + "is your card."); input.close(); return won; } }