Question: Help with Java progam! Some code given, but I would like to have a program in Java in how to do this magic trick. Any

Help with Java progam! Some code given, but I would like to have a program in Java in how to do this magic trick. Any and all help greatly appreciated!

1. write a Java program that converts a positive integer into ternary (base three) digits.

import java.util.*;

import java.io.*;

public class Ternary_Based {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int TernaryAnswer = 0;

int input;

System.out.println("Enter input: ");

input = sc.nextInt();

sc.close();

int factor = 1;

while (input > 0) {

TernaryAnswer += input % 3 * factor;

input /= 3;

factor *= 10;

}

System.out.println(TernaryAnswer)

}

}

I think this should all be good (I'm very new to Java). Next step for my program:

2. Use Java (Eclipse) to model a deck of card so it can act as a tutor for the following magic trick:

Your program will display step-by-step instructions, with a working example. If run again, the instructions should remain consistent, but the example will change (randomly*).

Instructions:

1. The observer (or magician) shuffles the deck and deals out the first 27 cards. The remaining cards are not used for the rest of the trick.

2. The observer selects any one card from the newly shuffled 27-card deck. (Console input, perhaps the position of the card in the 27.) The observer remembers her card without showing the magician. (In programming terms, that means you can do nothing with the value remembered other than acting as the observer in what follows. That is, you cant use the value to force the trick to work.)

3. The chosen card is returned to the deck. (In your program, it never left the deck.)

4. The observer picks a number between 1 & 27, call it luckyNum. (Generate a random integer in that range and display the number the user choose.)

5. While the observer shuffles the deck of 27, the magician does some figuring a. BTnum = luckyNum 1 // number of cards I want on top of selected card b. Convert BTnum into three base-three digits: LMF3 c. The digits are used is reverse order (least to most significant digit) to make an ordering decision later. Note that if you get this wrong FML takes on the usual texters meaning.

6. The magician does the following three times a. Deals out cards sequentially into three piles, face up. b. The observer identifies the pile containing the (unknown to the magician) selected card. c. The magician picks up the three piles, resequencing the cards following the rule below based on the observer identifying the pile containing her card. (The order of the two remaining piles of nine is not significant.) i. On the first iteration, 1. if F is a 0, the identified nine card pile goes on top 2. if F is a 1, the identified nine card pile goes in the middle 3. if F is a 2, the identified nine card pile goes on the bottom ii. On the second iteration, same decision for M iii. On the third iteration, same decision for L d. The magician then reveals the cards sequentially, counting to luckyNum and stops, showing that the card in position luckyNum is the users secretly selected card. Cards should be displayed simply as two chars: 2S,3H,4C,5D,6S,7H,8C,9D,TS,JH,QC,KD,AS * The randomness comes from a shuffle of the deck (and the selection of the lucky number). One way to shuffle N numbers in an array for cnt from 0 to N-1 choose M randomly, such that 0

https://youtu.be/l7lP9y7Bb5g - Your program is acting as a tutor for the trick methodology. This youtube video is what I am trying to program.

Here's the card stacks

Help with Java progam! Some code given, but I would like to

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!