Question
Java: Coin Automata Problem Set: A grid has been established below where we place a marker on the circle numbered 1. We will toss a
Java: Coin Automata
Problem Set: A grid has been established below where we place a marker on the circle numbered 1. We will toss a coin. If the coin toss resulted in a 'heads', we would move the marker along the path labeled 'H' to the circle numbered 5. If the coin toss resulted in a 'tails', we would move the marker along the path labeled 'T' to the circle numbered 4. Based on the grid established the coin tosses are repeated again to move the marker accordingly. The purpose of this problem is to simulate this automata and to report the number of the circle on which the marker ends after a series of coin tosses.
The marker always begins on the circle numbered 1.
Input: Java should accept a string consisting only of the characters 'h' (heads) or 't' (tails), where each character represents the outcome of a coin toss. The string is terminated by a '#' character. Each character of the string triggers a move of the marker according to the grid above. Java should continue to prompt strings until a 'q' is entered for the string where the program should terminate without any further output.
Example Output:
Enter tosses: hhhtthththtttthht#
The marker ends on circle 3
Enter tosses: hththththt#
The marker ends on circle 6
Enter tosses: q
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started